C++ || Java || Python3
cpp []\nclass Solution {\npublic:\n    string decodeCiphertext(string encodedText, int rows) {\n        int n = encodedText.size();\n        if (rows == 0 || n 
```cpp []\nclass Solution {\npublic:\n    string decodeCiphertext(string encodedText, int rows) {\n        int n = encodedText.size();\n        if (rows == 0 || n == 0) return "";\n        \n        int cols = n / rows;\n        vector<vector<char>> mat(rows, vector<char>(cols, \' \'));\n        int k = 0;\n\n        for (int i = 0; i < rows; i++) {\n            for (int j = 0; j < cols; j++) {\n                if (k < n) {\n                    mat[i][j] = encodedText[k++];\n                }\n            }\n        }\n        string ans = "";\n        int i = 0, j = 0;\n        while (i < rows && j < cols) {\n            ans.push_back(mat[i][j]);\n            i++;\n            j++;\n\n            if (i == rows || j == cols) {\n                j -= (i - 1);\n                i = 0;\n            }\n        }\n        while (!ans.empty() && ans.back() == \' \') {\n            ans.pop_back();\n        }\n        return ans;\n    }\n};\n\n// Runtime: 45ms Beats 100.00%\n// Memory: 47.53MB Beats 21.43%\n```\n```Java []\nclass Solution {\n    public String decodeCiphertext(String encodedText, int rows) {\n        int n = encodedText.length();\n        if (rows == 0 || n == 0) return"";\n\n        int cols = n / rows;\n        char[][] mat = new char[rows][cols];\n        int k = 0;\n\n        for (int i = 0; i < rows; i++) {\n            for (int j = 0; j < cols; j++) {\n                if (k < n) {\n                    mat[i][j] = encodedText.charAt(k++);\n                } else {\n                    mat[i][j] = \' \';\n                }\n            }\n        }\n        StringBuilder ans = new StringBuilder();\n        int i = 0, j = 0;\n\n        while (i < rows && j < cols) {\n            ans.append(mat[i][j]);\n            i++;\n            j++;\n\n            if ( i == rows || j == cols) {\n                j -= (i - 1);\n                i = 0;\n            }\n        }\n        while (ans.length() > 0 && ans.charAt(ans.length() - 1) == \' \') {\n            ans.deleteCharAt(ans.length() - 1);\n        }\n        return ans.toString();\n    }\n}\n\n// Runtime: 43ms Beats 32.00%\n// Memory: 55.27MB Beats 50.00%\n```\n```Python3 []\nclass Solution:\n    def decodeCiphertext(self, encodedText: str, rows: int) -> str:\n        n = len(encodedText)\n        if rows == 0 or n == 0:\n            return ""\n        \n        cols = n // rows\n        mat = [[\' \' for _ in range(cols)] for _ in range(rows)]\n        k = 0\n\n        for i in range(rows):\n            for j in range(cols):\n                if k < n:\n                    mat[i][j] = encodedText[k]\n                    k += 1\n                else:\n                    mat[i][j] = \' \'\n        ans = []\n        i, j = 0, 0\n\n        while i < rows and j < cols:\n            ans.append(mat[i][j])\n            i += 1\n            j += 1\n\n            if i == rows or j == cols:\n                j -= (i - 1)\n                i = 0\n        while ans and ans[-1] == \' \':\n            ans.pop()\n        return \'\'.join(ans)\n\n# Runtime: 459ms Beats 15.50%\n# Memory: 37.28MB Beats 15.50%\n```
['C++', 'Java', 'Python3']