leetcode 30 days js challenge
Medium
2675. Array of Objects to Matrix
Write a function that converts an array of objects arr
into a matrix m
.
arr
is an array of objects or arrays. Each item in the array can be deeply nested with child arrays and child objects. It can also contain numbers, strings, booleans, and null values.
The first row m
should be the column names. If there is no nesting, the column names are the unique keys within the objects. If there is nesting, the column names are the respective paths in the object separated by "."
.
Each of the remaining rows corresponds to an object in arr
. Each value in the matrix corresponds to a value in an object. If a given object doesn't contain a value for a given column, the cell should contain an empty string ""
.
The colums in the matrix should be in lexographically ascending order.
Example 1:
Example 2:
Example 3:
Example 4:
Example 5:
Constraints:
1 <= arr.length <= 1000
unique keys <= 1000
Backtracking 解法:
SheepTues, May 23, 2023