Stable Unique Column Renames
Problem statement
Process a sequence of table-schema snapshots. Each snapshot lists the currently visible raw column names in display order.
The first time a raw name appears, replace every . with _. The assigned display name must be unique case-insensitively across every name ever assigned. If the normalized base is already used, append _1, _2, and so on using the smallest available suffix.
A raw name keeps its assigned display name when it moves, disappears, or reappears in a later snapshot. Assigned names are never recycled. Return the renamed columns for every snapshot in the same shape and order.
Function
stableColumnNames(snapshots: String[][]) → String[][]Examples
Example 1
snapshots = [["user.id","user_id"],["user_id","user.id"]]return = [["user_id","user_id_1"],["user_id_1","user_id"]]The colliding raw names keep their first assigned names after reordering.
Example 2
snapshots = [["A"],["a"],["A"]]return = [["A"],["a_1"],["A"]]Uniqueness is case-insensitive while exact raw-name identity is persistent.
Constraints
0 <= snapshots.length <= 10000.- The total number of column occurrences is at most
200000. - Raw names are nonempty and unique within one snapshot.
- Raw names contain letters, digits, underscores, and periods.