Print Words Vertically - Problem
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 would be put on only one column and that in one column there will be only one word.
Input & Output
Example 1 — Basic Case
$
Input:
s = "HOW ARE YOU"
›
Output:
["HAY","ORU","WE"]
💡 Note:
Reading vertically: Column 0 = H+A+Y = "HAY", Column 1 = O+R+U = "ORU", Column 2 = W+E = "WE" (no trailing spaces)
Example 2 — Different Lengths
$
Input:
s = "TO BE OR NOT TO BE"
›
Output:
["TBONTB","OEROOE"," T NT "," I "]
💡 Note:
Words have varying lengths, shorter words contribute spaces. Column 2 has internal spaces but no trailing spaces.
Example 3 — Single Word
$
Input:
s = "CONTEST"
›
Output:
["C","O","N","T","E","S","T"]
💡 Note:
Single word becomes vertical - each character forms its own column
Constraints
- 1 ≤ s.length ≤ 200
- s contains only upper case English letters
- It's guaranteed that there is only one space between 2 words
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code