Problem statement

https://binarysearch.com/problems/Vertical-Word-Arrangement/

Solution

Just do what is asked.

Complexity

It is O(mn) for time and space, where m is the biggest part in split and n is number of parts.

Code

class Solution:
    def solve(self, s):
        parts = s.split()
        ans = []
        m, n = max(len(x) for x in parts), len(parts)
        for j in range(m):
            col = [parts[i][j] if j < len(parts[i]) else " " for i in range(n)]
            ans += ["".join(col).rstrip(" ")]
        return ans