Array of Objects to Matrix - Problem
Transform an array of nested objects into a structured matrix format! This problem challenges you to flatten complex, deeply nested data structures into a readable tabular format.
Given an array arr containing objects or arrays with potentially deep nesting (including child arrays, objects, numbers, strings, booleans, and null values), your task is to:
- Extract all possible paths from the nested structures
- Create column headers using dot notation for nested paths (e.g.,
"user.address.city") - Build a matrix where the first row contains sorted column names
- Populate data rows with values from each object, using empty strings for missing values
The columns must be arranged in lexicographically ascending order, making the output predictable and organized.
Example: [{"name": "John", "address": {"city": "NYC"}}, {"name": "Jane", "age": 25}] becomes a matrix with headers ["address.city", "age", "name"] and corresponding data rows.
Input & Output
example_1.py — Basic Objects
$
Input:
[{"b": 1, "a": 2}, {"c": 3, "a": 4}]
›
Output:
[["a", "b", "c"], ["2", "1", ""], ["4", "", "3"]]
💡 Note:
Two objects with different keys. Columns sorted: a, b, c. Missing values filled with empty strings.
Constraints
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code