Code RoomPivot with gaps filled
HardPrep Room Coding #5138

Pivot with gaps filled

CodingAlgorithms & data structuresSenior–Staff~12 min

Given `marks` with columns `student`, `subject` and `score`, build a table of the MEAN score for every student and subject pair, using 0 where a pair is missing. Return `student`, `math` and `science`, sorted by `student` ascending.

Implement
mean_grid(marks: dataframe) → dataframe
Examples
in[{"__df__":[{"score":88,"student":"ana","subject":"math"},{"score":92,"student":"ana","subject":"science"},{"score":75,"student":"ben","subject":"math"},{"score":64,"student":"ben","subject":"science"},{"score":95,"student":"cara","subject":"math"},{"score":81,"student":"cara","subject":"science"},{"score":100,"student":"ana","subject":"math"}]}]out[{"math":94,"science":92,"student":"ana"},{"math":75,"science":64,"student":"ben"},{"math":95,"science":81,"student":"cara"}]
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 12 min
InputExpectedGot
[{"__df__":[{"score":88,"student":"ana","subject":"math"},{"score":92,"student":"ana","subject":"science"},{"score":75,"student":"ben","subject":"math"},{"score":64,"student":"ben","subject":"science"},{"score":95,"student":"cara","subject":"math"},{"score":81,"student":"cara","subject":"science"},{"score":100,"student":"ana","subject":"math"}]}][{"math":94,"science":92,"student":"ana"},{"math":75,"science":64,"student":"ben"},{"math":95,"science":81,"student":"cara"}]not run yetsample