Group by and count
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]) → listExamples
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
solution.py
InputExpectedGot
[[3,1,3,2,1,3]][3,[[1,2],[2,1],[3,3]]]not run yetsample