Reported May 2017
ZipRecruitersimulation

Iterate Ragged Integer Lists Vertically

Reported by candidates from ZipRecruiter's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live ZipRecruiter OA. Under 2s to a working solution.
Founder's read

The mistake that sinks a first attempt on this ZipRecruiter OA, reported in May 2017, is assuming the grid is rectangular. It isn't. You get a ragged list of integer lists and have to read it column by column, skipping rows that are too short. It's a simulation problem with array indexing, and it looks easy until a short row throws an index error. If you blank on the loop bounds, StealthCoder runs invisibly during the live assessment as a safety net. Read the trick below first, though. It takes about ten lines.

The problem

rows is a possibly ragged list of integer lists. Read it one column at a time from left to right. Within a column, emit existing values from the first row to the last row.
Skip a row when it has no value in the current column. Return the complete vertical order.

Function
verticalIteration(rows: int[][]) → int[]

Examples
Example 1
rows = [[1,2,3],[4,5],[6]]
return = [1,4,6,2,5,3]
Columns are traversed left to right and absent cells are skipped.
Example 2
rows = [[1,2],[3,4]]
return = [1,3,2,4]
A rectangular matrix is read column-major.

Constraints
0 <= rows.length <= 10000
The total number of integers is at most 100000.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is that the number of columns is the length of the longest row, not the first row. Loop col from 0 to maxLen - 1. Inside, loop each row and append rows[r][col] only if col < rows[r].length. That's the whole algorithm. The common pitfall is using rows[0].length as the width, which drops values when a later row is longer, or crashes when you index past the end of a short row. Also handle empty input, where rows.length is 0 and you return an empty array. Complexity is O(maxLen * rows) in the worst case, which can be wasteful if one row is huge and the rest are tiny. With at most 100000 integers and 10000 rows, a long skinny shape could be slow. A cleaner option is a queue of row indices that still have values, or bucketing values by column in one pass. If you freeze in the live OA, StealthCoder can hand you the working version.

The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.

If this hits your live OA

You can drill Iterate Ragged Integer Lists Vertically cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass ZipRecruiter's OA.

ZipRecruiter reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Iterate Ragged Integer Lists Vertically FAQ

How hard is this ZipRecruiter problem really?+

Easy. It's a simulation with two nested loops and one bounds check. The difficulty is in the edge cases: empty input, empty inner lists, and rows of very different lengths. If you handle those, you're done in a few minutes.

What's the trick to vertical iteration on ragged lists?+

Compute the maximum row length, then iterate columns from 0 to that max. For each column, scan rows top to bottom and only take a value if the row is long enough. Never assume the first row sets the width.

Will the naive column-by-column loop time out?+

It can in a bad case. If one row has 90000 values and 10000 rows are tiny, you scan every row for every column. A safer approach is to keep only the rows that still have values, or bucket values by column index in a single pass.

What edge cases should I test before submitting?+

Test an empty outer list, rows containing empty lists, a single row, a single column, and a long row after short ones. Also check that the order within a column follows row order, matching the first example output.

How do I prepare for this in 48 hours?+

Write the nested-loop version from memory, then the bucket-by-column version. Practice jagged-array traversal like diagonal and zigzag reads, since they share the same indexing habits. Spend the rest of your time on timing and edge cases rather than new topics.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with ZipRecruiter.

OA at ZipRecruiter?
Invisible during screen share
Get it