Print Words Vertically
A medium-tier problem at 66% community acceptance, tagged with Array, String, Simulation. Reported in interviews at Guidewire and 0 others.
Print Words Vertically is a medium-difficulty string and array problem that appears straightforward until you hit edge cases during the assessment. You're given a string, split it into words, and print each character column by column from top to bottom. Guidewire has asked this one. The trap: trailing spaces. Most candidates build the output correctly but fail test cases because they either include trailing whitespace they shouldn't, or strip it when the problem expects it. If this hits your live OA and you blank on the whitespace rule, StealthCoder surfaces a working solution in seconds, invisible to the proctor.
Companies that ask "Print Words Vertically"
Print Words Vertically is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built by an engineer at a top-10 tech company who can solve these problems cold but didn't want to trust himself in a 90-minute screen share.
Get StealthCoderThe core pattern is simulation. Iterate through each character position across all words, collect characters at that index, and build output rows. The real work is managing variable word lengths and trailing spaces on each row. Many candidates write clean code that passes the basic case but fails when word lengths differ significantly or when the rightmost word is shorter than others on certain rows. You need to trim trailing spaces from each output line, but not leading spaces. The algorithm itself is O(n * m) where n is word count and m is max word length. Array and string manipulation combine here. Common mistakes: forgetting to strip right-side whitespace per line, or accidentally stripping necessary internal spacing. This is where the gap between "it works locally" and "it passes all test cases" lives.
Pattern tags
You know the problem.
Make sure you actually pass it.
Print Words Vertically recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built by an engineer at a top-10 tech company who can solve these problems cold but didn't want to trust himself in a 90-minute screen share. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Print Words Vertically interview FAQ
Is this problem really asked at Guidewire?+
Yes. Guidewire reports asking it. It's a medium problem, so expect it in a live assessment or take-home coding round, not a phone screen. The acceptance rate sits at 66 percent, which means roughly one-third of submitters miss something, likely the whitespace handling on edge cases.
What's the trick I need to know before the OA?+
Trim trailing spaces from each output row, but preserve leading spaces and internal spacing. Build your character grid correctly, then clean each line. Many solutions fail because they either keep trailing whitespace or strip too aggressively. Test with words of different lengths.
Does this involve sorting or complex data structures?+
No. It's pure simulation and string handling. You don't need a heap, hash map, or sorting algorithm. Arrays and strings only. The difficulty comes from careful index management and understanding what whitespace to keep or remove, not from algorithmic complexity.
How does Print Words Vertically relate to the other Array and String topics?+
Array teaches index iteration and bounds checking. String teaches character manipulation and whitespace handling. This problem combines both: iterating through a 2D logical structure (words and their characters) and building clean string output. It's a gentle introduction to coordinate-based simulation.
What's the time and space complexity I should aim for?+
Time is O(n * m) where n is word count and m is the longest word length, because you visit each character once. Space is O(n * m) for the output grid and result. You can't do better because the output itself is that size. No tricks here, just honest work.
Want the actual problem statement? View "Print Words Vertically" on LeetCode →