FastPrepMerge Timestamped Record Lists

Merge Timestamped Record Lists

Nuro logoNuro● MediumFULLTIMEPHONE SCREEN
Learn

Problem statement

You are given several record lists. Every record has an integer timestamp and an opaque string payload. Each list is already sorted by timestamp in nondecreasing order. Merge all records into one ordered list without dropping or changing any payload.

For this exercise, the input uses two aligned arrays: timestamps[i][j] is the timestamp of record j in list i, and payloads[i][j] is that record's payload. The two arrays have identical row lengths.

  • Order records by timestamp ascending.
  • For equal timestamps, records from a smaller input-list index come first.
  • Within one list, equal-timestamp records keep their original order.
  • Retain every occurrence, including identical timestamps and identical payloads. Treat payloads as opaque data, not as sorting keys.

Return a String[][] array. Each output row is [timestampText, payload], where timestampText is the timestamp written in base 10 with no leading zeroes. Return an empty array when there are no records. The inputs need not be modified.

The aligned arrays are a finite representation of the reported timestamp-and-payload record lists; an implementation may use a record or cursor structure internally.

Function

mergeTimestampedRecords(timestamps: int[][], payloads: String[][]) → String[][]

Examples

Example 1

timestamps = [[1,4],[2,3]]payloads = [["a","d"],["b","c"]]return = [["1","a"],["2","b"],["3","c"],["4","d"]]

The timestamp order interleaves the two input lists. Each payload stays attached to its timestamp.

Example 2

timestamps = [[5,5],[5],[]]payloads = [["left0","left1"],["right0"],[]]return = [["5","left0"],["5","left1"],["5","right0"]]

At timestamp 5, list 0 precedes list 1, and its two records retain their original order. The empty list contributes nothing.

Example 3

timestamps = []payloads = []return = []

No input lists means no records to return.

Constraints

  • 0 <= timestamps.length = payloads.length <= 500.
  • For every list i, timestamps[i].length = payloads[i].length.
  • The total number of records across all lists is at most 2000. Lists may be empty.
  • -10^9 <= timestamps[i][j] <= 10^9; each timestamp row is nondecreasing.
  • Each payload contains from 0 through 40 printable ASCII characters. Spaces, punctuation and empty payloads are valid.

More Nuro problems

See Nuro hiring insights
public String[][] mergeTimestampedRecords(int[][] timestamps, String[][] payloads) {
    // Write your code here.
}
timestamps[[1,4],[2,3]]
payloads[["a","d"],["b","c"]]
expected[["1", "a"], ["2", "b"], ["3", "c"], ["4", "d"]]
Checking account…