FastPrepMerge K Sorted Sequences
Problems/Merge K Sorted Sequences

Merge K Sorted Sequences

Headlands Technologies logoHeadlands Technologies● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in the first task of a Headlands Technologies phone screen. The task was merging K sorted lists, dressed up as a stock-trading problem. The report does not give the stock fields, the API or the limits. Here you merge arrays of integer sort keys and keep every duplicate. The report also had a separate task about an asynchronous client and concurrency. We left that out. We chose the function signature, the limits, the solutions and the examples. Our version is about 70% the same as the reported question.

You are given sequences, an array of integer sequences. Each sequence is already sorted from smallest to largest. Merge all their entries into one array, also sorted from smallest to largest.

Keep every entry exactly once, so duplicates stay in the result. Some sequences may be empty. If there are no entries at all, return an empty array. Do not change any input sequence.

Equal values look the same in the output, so you do not need any rule for ordering them. In the interview story, the numbers are the sort keys of stock records. You only work with the keys: there are no trading orders, prices, client requests or concurrent workers to handle.

Function

mergeSortedSequences(sequences: int[][]) → int[]

Examples

Example 1

sequences = [[1,4,7],[2,5,8],[3,6,9]]return = [1,2,3,4,5,6,7,8,9]

Each row is sorted, but the values of the rows take turns. Picking the smallest front value each time gives 1 through 9.

Example 2

sequences = [[],[-5,-5,4],[-5,0],[]]return = [-5,-5,-5,0,4]

Empty rows contribute nothing. Preserve all three occurrences of -5, followed by 0 and 4.

Example 3

sequences = []return = []

There are no sequences, so the result is an empty array.

Constraints

  • 0 <= sequences.length <= 100.
  • The total number of entries across all rows is at most 2000.
  • Each row is sorted; every value is an integer in [-10^9,10^9].
  • Rows contain no null values. All output values fit signed 32-bit integers.

More Headlands Technologies Phone Screen questions

  • Integer Compression OffsetPHONE SCREEN · Seen Oct 2026
  • Market Order BookPHONE SCREEN · Seen Jun 2026
  • Gradient Descent on a Sinusoidal ObjectivePHONE SCREEN · Seen Apr 2026
  • Pearson Correlation CoefficientPHONE SCREEN · Seen Apr 2026
  • Top K Frequent ElementsPHONE SCREEN · Seen Apr 2026
  • Queue Mean from Corrective SnapshotsPHONE SCREEN · Seen Mar 2026
  • Queue Mean QueriesPHONE SCREEN · Seen Mar 2026
  • CPU Register Bitwise OperationsPHONE SCREEN · Seen Nov 2025
  • Top Trade Events by NotionalPHONE SCREEN · Seen May 2024
  • Fixed-Size Memory PoolPHONE SCREEN · Seen May 2024

Similar questions at other companies

  • Top K Frequent ElementsAmazon · OA · PHONE SCREEN · ONSITE INTERVIEW
  • Mutual-Friend RecommendationsMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
  • Tennis Court SchedulingAtlassian · PHONE SCREEN · ONSITE INTERVIEWAtlassian interview questions
  • Maximum Number of Events That Can Be AttendedByteDance · PHONE SCREENByteDance interview questions
  • Meeting Rooms IIeBay · PHONE SCREENeBay interview questions
  • Select the Top User MatchesDuolingo · PHONE SCREENDuolingo interview questions
  • Meeting Rooms IIQuince · PHONE SCREENQuince interview questions
  • Kth Largest Element in an ArrayLinkedIn · PHONE SCREENLinkedIn interview questions
  • Meeting Rooms IISecuronix · PHONE SCREEN
  • Merge Multiple Sorted StreamsNVIDIA · PHONE SCREENNVIDIA interview questions
All Headlands Technologies interview questionsSee Headlands Technologies hiring insights
Saved
class Solution {
    public int[] mergeSortedSequences(int[][] sequences) {
        // write your code here
    }
}
Checking account…