FastPrepIterate Ragged Integer Lists Vertically

Iterate Ragged Integer Lists Vertically

ZipRecruiter logoZipRecruiter● EasyNEW GRADONSITE INTERVIEW
Learn

Problem statement

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.

More ZipRecruiter problems

See ZipRecruiter hiring insights
public int[] verticalIteration(int[][] rows) {
    // Write your code here.
}
rows[[1,2,3],[4,5],[6]]
expected[1,4,6,2,5,3]
Checking account…