Beats 89% on Run and 100% on Memory
Intuition\n Describe your first thoughts on how to solve this problem. \nWe can determine the number of columns in the imaginary cipher matrix by taking the len
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe can determine the number of columns in the imaginary cipher matrix by taking the length of the encoded text and dividing by the rows. With this information we can see that to read the cipher on the matrix, if you move num cols + 1 cells on the cipher matrix we get to the decoded value. When we reach the end of the cipher this pattern breaks and we just move to the next column so a diag variable is used to track that. Lastly we repeat the decoding process a number of times equal to however many non whitespace chars exist in encoded text and keep track of whenever we decode a non whitespace char.\n\nLastly for efficiency if rows is 1 we can return the message as it is the answer.\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution(object):\n    def decodeCiphertext(self, encodedText, rows):\n        """\n        :type encodedText: str\n        :type rows: int\n        :rtype: str\n        """\n        lengthy = len(encodedText)\n        cols = lengthy / rows\n        decoded = ""\n        j = 0\n        diag = 0\n        i = 0\n        if(rows == 1):\n            return encodedText\n        repeat = encodedText.count(" ")\n        while i < (lengthy - repeat):\n            decoded+= encodedText[j]\n            if encodedText[j] != " ":\n                i+=1\n            j += cols+1\n            if j > lengthy:\n                diag +=1\n                j = diag\n        return decoded\n        \n```
['Python']