[Java/C++/Python] Soluiton with Explanation
Observations\n1. s.length() = rows * cols\n2. s[i] and s[i+cols+1] are adjacent characters in original text.\nFor example,\n"cipher" to "ch   ie   pr", cols = 3
# **Observations**\n1. `s.length() = rows * cols`\n2. `s[i]` and `s[i+cols+1]` are adjacent characters in original text.\nFor example,\n`"cipher"` to `"ch   ie   pr"`, `cols = 3`\n`s[0] = \'c\'`\n`s[4] = \'i\'`\n`s[8] = \'p\'`\n<br>\n\n# **Explanation**\nFor every character in the first row in the matrix,\nfind it\'s adjacent characters in diagonal position in the matrix.\nRead all these chara one by one,\nreturn the trimmed result string.\n<br>\n\n# **Complexity**\nTime `O(n)`\nSpace `O(n)`\n<br>\n\n**Java**\n```java\n    public String decodeCiphertext(String s, int rows) {\n        int n = s.length(), cols = n / rows;\n        StringBuilder res = new StringBuilder(10);\n        for (int i = 0; i < cols; ++i)\n            for (int j = i; j < n; j += cols + 1)\n                res.append(s.charAt(j));\n        while (res.length()  > 0 && res.charAt(res.length() - 1) == \' \')\n            res.setLength(res.length() - 1);\n        return res.toString();\n    }\n```\n\n**C++**\n```cpp\n    string decodeCiphertext(string s, int rows) {\n        int n = s.size(), cols = n / rows;\n        string res;\n        for (int i = 0; i < cols; ++i)\n            for (int j = i; j < n; j += cols + 1)\n                res += s[j];\n        while (res.back() == \' \')\n            res.pop_back();\n        return res;\n    }\n```\n\n**Python**\n```py\n    def decodeCiphertext(self, s, n):\n        m = len(s) / n\n        res = []\n        for i in xrange(m):\n            while i < len(s):\n                res.append(s[i])\n                i += m + 1\n        return \'\'.join(res).rstrip()\n```\n
[]