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
Time & Space Complexity
n*d for processing objects, m² for dynamic column insertions in worst case
Result matrix plus temporary path storage