Unpivot wide format to long
Given `wide` with columns `student`, `math` and `science`, turn the two subject columns back into rows. Return `student`, `subject` and `score`, sorted by `student` ascending and then `subject` ascending.
Implement
long_marks(wide: dataframe) → dataframeExamples
in
[{"__df__":[{"math":88,"science":92,"student":"ana"},{"math":75,"science":64,"student":"ben"}]}]out[{"score":88,"student":"ana","subject":"math"},{"score":92,"student":"ana","subject":"science"},{"score":75,"student":"ben","subject":"math"},{"score":64,"student":"ben","subject":"science"}]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__":[{"math":88,"science":92,"student":"ana"},{"math":75,"science":64,"student":"ben"}]}][{"score":88,"student":"ana","subject":"math"},{"score":92,"student":"ana","subject":"science"},{"score":75,"student":"ben","subject":"math"},{"score":64,"student":"ben","subject":"science"}]not run yetsample