---
# System prepended metadata

title: 2075. Decode the Slanted Ciphertext
tags: [Leetcode, String, Medium]

---

# 2075. Decode the Slanted Ciphertext
###### tags: `Leetcode` `Medium` `String`
Link: https://leetcode.com/problems/decode-the-slanted-ciphertext/description/
## Code
```java=
class Solution {
    public String decodeCiphertext(String encodedText, int rows) {
        int n = encodedText.length();
        StringBuilder sb = new StringBuilder();
        int cols = n/rows;
        for(int i=0; i<cols; i++){
            for(int j=i; j<n; j+=cols+1){
                sb.append(encodedText.charAt(j));
            }
        }
        while(sb.length()>0 && sb.charAt(sb.length()-1)==' '){
            sb.setLength(sb.length()-1);
        }
        return sb.toString();
    }
}
```