FastPrepChunked Round-Robin Row Traversal

Chunked Round-Robin Row Traversal

Motive logoMotive● MediumFULLTIMEPHONE SCREEN
Learn

Problem statement

Given a jagged matrix rows and a positive chunkSize, visit active rows in their original order. On each visit, append up to chunkSize remaining values from that row. Continue cycling until every row is exhausted, and return the traversal.

Function

roundRobinRows(rows: int[][], chunkSize: int) → int[]

Examples

Example 1

rows = [[1,2,3,4],[5,6],[7,8,9],[10]]chunkSize = 2return = [1,2,5,6,7,8,10,3,4,9]

Example 2

rows = [[],[1,2],[3]]chunkSize = 1return = [1,3,2]

Constraints

  • 0 <= rows.length <= 1000.
  • The total number of values is at most 100000.
  • 1 <= chunkSize <= 100000.

More Motive problems

See Motive hiring insights
public int[] roundRobinRows(int[][] rows, int chunkSize) {
  // write your code here
}
rows[[1,2,3,4],[5,6],[7,8,9],[10]]
chunkSize2
expected[1,2,5,6,7,8,10,3,4,9]
Checking account…