Ctrl K

Words Read Down the Columns

Medium
You are given a phrase: words of uppercase English letters separated by exactly one space. Write each word top to bottom in its own column (the first word in the first column, the second in the second, and so on), then read the resulting table row by row. Return the rows of the table from top to bottom. When a word is too short to reach a row, its spot holds a space. Rows must not end with spaces; strip them.
Example 1
phrase="CAT ON MAT" → ['COM', 'ANA', 'T T']

Row one holds the first letters (C, O, M), row two the second ones (A, N, A), row three the third ones: ON has none, so that spot is a space, followed by the T of MAT.

Example 2
phrase="SKY IS BLUE" → ['SIB', 'KSL', 'Y U', '  E']

Row three has Y, then a space where IS has no letter, then U; row four has two spaces before E. Trailing spaces are removed.

Constraints
  • 1 ≤ len(phrase) ≤ 200
  • phrase consists of uppercase English letters and spaces
  • Words are separated by exactly one space, with no leading or trailing spaces
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsSplit Text at the Marks MediumJustify the Lines HardA One-Variable Language EasySimultaneous Chess Moves HardMirrored Codes Easy
loading Python…
Input
phrase="CAT ON MAT"
Expected
['COM', 'ANA', 'T T']

Run checks the first 3 tests in your browser. Submit checks all 127 tests on the server, hidden ones included.