FastPrepConvert Sparse Records to a Filled Table
Problems/Convert Sparse Records to a Filled Table

Convert Sparse Records to a Filled Table

Netflix logoNetflix● MediumNEW GRADOA
QuestionFunctionExamplesConstraints

Problem statement

Source note: The interview report asks to turn records with varying key sets into a table and to fill missing fields. It omits column order and the empty case; this practice version sorts the union of keys and returns an explicit header row. The judged core task matches the visible report at about 85%.

Each record is represented by parallel arrays keysByRow[i] and valuesByRow[i]. Keys are unique within a record, while different records may contain different keys.

Return a rectangular table. Its first row is the lexicographically sorted union of all keys. Every following row corresponds to one input record in original order and contains its value under each header key, or fill when that key is absent.

If there are no records, return one empty header row.

Function

recordsToTable(keysByRow: String[][], valuesByRow: String[][], fill: String) → String[][]

Examples

Example 1

keysByRow = [["name","age"],["name","city"]]valuesByRow = [["Ada","36"],["Lin","Paris"]]fill = ""return = [["age","city","name"],["36","","Ada"],["","Paris","Lin"]]

The header is the sorted key union and missing cells use fill.

Example 2

keysByRow = [["b"],[],["a","b"]]valuesByRow = [["2"],[],["1","3"]]fill = "NA"return = [["a","b"],["NA","2"],["NA","NA"],["1","3"]]

Empty records still produce a fully filled row.

Example 3

keysByRow = []valuesByRow = []fill = "x"return = [[]]

With no records, the table contains only an empty header.

Constraints

  • 0 <= keysByRow.length == valuesByRow.length <= 100000.
  • For each row, key and value counts are equal and keys are unique.
  • Keys are nonempty case-sensitive strings of at most 100 characters.
  • The total number of key-value pairs is at most 200000.

More Netflix problems

  • Timed Cache with Sidecar CleanupPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Repeated Titles in Viewing HistoryPHONE SCREEN · Seen Sep 2026
  • Score-Rotating Movie PlaylistONSITE INTERVIEW · Seen Sep 2026
All Netflix interview questionsSee Netflix hiring insights
Saved
class Solution {
    public String[][] recordsToTable(String[][] keysByRow, String[][] valuesByRow, String fill) {
        // Write your solution here.
    }
}
Checking account…