[JAVA] O(N) Solution
\nclass Solution {\n    public String decodeCiphertext(String encodedText, int rows) {\n        StringBuilder sb = new StringBuilder();\n        \n        char[
```\nclass Solution {\n    public String decodeCiphertext(String encodedText, int rows) {\n        StringBuilder sb = new StringBuilder();\n        \n        char[] chars = encodedText.toCharArray();\n        \n        int cols = chars.length / rows;\n        \n        int i = 0;\n        int j = 0;\n        //use this variable to reset j\'s value.\n        int counter = 0;\n        \n        while (j < cols) {\n            while (i < rows && j < cols) {\n                int arrayIndex = i * cols + j;\n                sb.append(chars[arrayIndex]);\n                i++;\n                j++;\n            }\n            counter++;\n            \n            i = 0;\n            j = counter;\n        }\n        \n        return removeSpaces(sb).toString();\n    }\n    \n    private StringBuilder removeSpaces(StringBuilder sb) {\n        if (sb.length() < 1) return sb;\n        \n        while(sb.charAt(sb.length() - 1) == \' \') {\n            sb.deleteCharAt(sb.length() - 1);\n        }\n        \n        return sb;\n    }\n}\n```
[]