#1324
Print Words Vertically
specialist · 610 · lc medium +29 · verified · 67.4% accepted · 824 likes · top 74%
Description
Given a string s of space-separated words, print them vertically column by column in their original order. Each column holds exactly one word; pad shorter words with spaces where necessary, but remove any trailing spaces from each row. Return the list of rows.
Example 1:
Input: s = "HOW ARE YOU"
Output: ["HAY","ORO","WEU"]
Explanation: Each word is printed vertically.
"HAY"
"ORO"
"WEU"
Example 2:
Input: s = "TO BE OR NOT TO BE"
Output: ["TBONTB","OEROOE"," T"]
Explanation: Trailing spaces is not allowed.
"TBONTB"
"OEROOE"
" T"
Example 3:
Input: s = "CONTEST IS COMING"
Output: ["CIC","OSO","N M","T I","E N","S G","T"]
Code
1
2
3