Code RoomGroup by and count
EasyPrep Room Coding #342

Group by and count

CodingDatabases & SQLMid~18 min

Implement SELECT value, COUNT(*) FROM t GROUP BY value plus a DISTINCT count. Given a list of integer values, return a pair [distinct_count, pairs] where distinct_count is the number of distinct values and pairs is a list of [value, count] for each distinct value, sorted by value ascending. Preserve exact occurrence counts. The input may be empty. Up to 100000 values.

Implement
distinct_with_count(values: list[int]) → list
Examples
in[[3,1,3,2,1,3]]out[3,[[1,2],[2,1],[3,3]]]
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 18 min
InputExpectedGot
[[3,1,3,2,1,3]][3,[[1,2],[2,1],[3,3]]]not run yetsample