Code RoomRow store vs column store
EasyPrep Room Coding #4738

Row store vs column store

CodingDatabases & SQLStorage & CDNEntry–Mid~15 min

An analytics warehouse keeps one table in two layouts, row by row and column by column, and you are sizing the same scan against both. columns describes the table, one entry per column written as "name|width", where width is the bytes a single value of that column occupies, and column names are unique. row_count is how many rows the table holds. projected names the columns the query reads: a name may appear more than once, and a name that is not a column of this table is ignored. A row store has to read whole rows, so it reads row_count times the total width of every column. A column store opens only the files of the projected columns, so it reads row_count times the total width of the distinct projected columns that exist. Return a two element list, the row store bytes first and the column store bytes second.

Implement
projection_scan_bytes(columns: list[str], row_count: int, projected: list[str]) → list[int]
Examples
in[["event_id|8","user_id|8","country|2","payload|512"],1000,["event_id","country"]]out[530000,10000]
in[["event_id|8","user_id|8","country|2","payload|512"],1000,["event_id","user_id","country","payload"]]out[530000,530000]
in[["event_id|8","user_id|8","country|2","payload|512"],1000,["payload","payload","missing"]]out[530000,512000]
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 15 min
InputExpectedGot
[["event_id|8","user_id|8","country|2","payload|512"],1000,["event_id","country"]][530000,10000]not run yetsample
[["event_id|8","user_id|8","country|2","payload|512"],1000,["event_id","user_id","country","payload"]][530000,530000]not run yetsample
[["event_id|8","user_id|8","country|2","payload|512"],1000,["payload","payload","missing"]][530000,512000]not run yetsample