Code RoomSafe columns to drop
HardPrep Room Coding #4880

Safe columns to drop

CodingDatabases & SQLAlgorithms & data structuresMid–Staff~35 min

A data team exports a table as rows of string cells, every row the same width. They want to know which single columns carry no distinguishing information. Dropping column j is safe when it merges nothing: any two rows that differ somewhere before the drop still differ somewhere after it. Rows may repeat in the export, and a repeated row was already identical to its twin, so repeats never block a drop. Cells hold arbitrary text and may contain commas, pipes, quotes or any other character, so any scheme that glues a row into a single string has to stay unambiguous. Given the table, return the indices of every safe column, sorted ascending. Return an empty list when the table has no rows or no columns.

Implement
droppable_columns(rows: list[list[str]]) → list[int]
Examples
in[[["a","1","x"],["a","2","x"],["b","1","x"]]]out[2]
in[[["a","b"],["a","b"]]]out[0,1]
in[[["one,two","three"],["one","two,three"]]]out[0,1]
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 35 min
InputExpectedGot
[[["a","1","x"],["a","2","x"],["b","1","x"]]][2]not run yetsample
[[["a","b"],["a","b"]]][0,1]not run yetsample
[[["one,two","three"],["one","two,three"]]][0,1]not run yetsample