Count nulls per column
Given `readings` with columns `device`, `ts` and `reading`, count the missing values in every column. Return `column` and `nulls`, one row per column, sorted by `column` ascending.
Implement
null_counts(readings: dataframe) → dataframeExamples
in
[{"__df__":[{"ts":"2024-05-01","device":"a1","reading":20.5},{"ts":"2024-05-02","device":"a1","reading":null},{"ts":"2024-05-03","device":"a1","reading":22.5},{"ts":"2024-05-01","device":"b2","reading":null},{"ts":"2024-05-02","device":"b2","reading":31},{"ts":"2024-05-03","device":"b2","reading":33}]}]out[{"nulls":0,"column":"device"},{"nulls":2,"column":"reading"},{"nulls":0,"column":"ts"}]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 9 min
solution.py
InputExpectedGot
[{"__df__":[{"ts":"2024-05-01","device":"a1","reading":20.5},{"ts":"2024-05-02","device":"a1","reading":null},{"ts":"2024-05-03","device":"a1","reading":22.5},{"ts":"2024-05-01","device":"b2","reading":null},{"ts":"2024-05-02","device":"b2","reading":31},{"ts":"2024-05-03","device":"b2","reading":33}]}][{"nulls":0,"column":"device"},{"nulls":2,"column":"reading"},{"nulls":0,"column":"ts"}]not run yetsample