This is a premium problem. We're working on making it available for free soon.
Explore Free ProblemsUse these hints if you're stuck. Try solving on your own first.
How could you split the problem up into sub-problems?
1.) Write a function that converts a single object into a dictionary that maps the path name to values. You can solve this recursively by keeping track of current path list.
2.) Write a function that converts a list of dictionaries into a matrix. Start by creating a list of all possible paths in any of the dictionaries. This will represent the columns.
Solutions for this premium problem will be available for free soon.
Browse Free ProblemsWatch expert explanations and walkthroughs
Jot down your thoughts, approach, and key learnings
Sorting ensures a consistent and deterministic column order for the matrix. Without sorting, the column order might vary depending on how keys are encountered in the objects.
Yes, variations of object-to-table or data transformation problems are common in FAANG-style interviews. They test understanding of data structures, iteration patterns, and clean handling of missing values.
A set is ideal for collecting unique keys efficiently, while arrays are used to construct the resulting matrix. Objects or maps help retrieve values quickly when building each row.
The optimal approach collects all unique keys from the objects using a set, sorts them to form the header row, and then iterates through each object to build rows aligned with those keys. Missing values are filled with empty strings to maintain the matrix structure.