Print Words Vertically

Given a string s, return all the words vertically in the same order in which they appear in s.

Words are returned as a list of strings, complete with spaces when necessary. Trailing spaces are not allowed.

Each word is put in only one column, and in one column there will be only one word.

Example 1
Inputs = "HOW ARE YOU"
Output["HAY","ORO","WEU"]
Each word is printed vertically, producing the rows "HAY", "ORO", and "WEU".
Example 2
Inputs = "TO BE OR NOT TO BE"
Output["TBONTB","OEROOE"," T"]
Trailing spaces are not allowed, so the final row keeps its needed leading spaces but removes trailing spaces.

Constraints

  • 1 <= s.length <= 200
  • s contains only upper case English letters.
  • It's guaranteed that there is only one space between 2 words.

Asked at 2 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate