Computing Next Position and Appending Characters Solution
Intuition\n Describe your first thoughts on how to solve this problem. \nThe next element in the string can be calculated by taking the current position + no. o
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe next element in the string can be calculated by taking the current position + no. of columns + 1. We need not create a grid of the string as shown in the example.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n- Calculate the number of columns in the string cipher.\n- Iterate through the first row only and for each element add the next element as current position + no. of columns + 1.\n- If we have trailing spaces, trim them.\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(n)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(n)\n\n# Code\n```\nclass Solution:\n    def decodeCiphertext(self, encodedText: str, rows: int) -> str:\n        \n        cols = len(encodedText) // rows\n\n        cipher = \'\'\n        for c in range(cols):\n            cipher += encodedText[c]\n            idx = c + cols + 1\n            while idx < len(encodedText):\n                cipher += encodedText[idx]\n                idx = idx + cols + 1\n        \n        # trim = 0\n        # for i in range(len(cipher) - 1, -1, -1):\n        #     if cipher[i] != \' \':\n        #         trim = i\n        #         break\n\n        return cipher.rstrip()\n```
['Python3']