Pivot marks to wide format
Given `marks` with columns `student`, `subject` and `score`, reshape it so each student has one row and each subject is its own column. Return `student`, `math` and `science`, sorted by `student` ascending.
Implement
wide_marks(marks: dataframe) → dataframeExamples
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"}]}]out[{"math":88,"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 10 min
solution.py
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"}]}][{"math":88,"science":92,"student":"ana"},{"math":75,"science":64,"student":"ben"},{"math":95,"science":81,"student":"cara"}]not run yetsample