Code RoomUnpivot wide format to long
MediumPrep Room Coding #5034

Unpivot wide format to long

CodingAlgorithms & data structuresMid–Senior~10 min

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) → dataframe
Examples
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
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