Common songs across playlists
A music service wants the songs that every one of its editorial playlists agrees on. Given a list of playlists, each a list of integer song ids (a playlist may repeat an id), return the ids that appear in every playlist, sorted ascending. If the outer list is empty, return an empty list; a single playlist returns its distinct ids sorted. For example, [[1, 2, 3], [2, 3, 4], [3, 2, 9]] returns [2, 3]. Intersecting lists pairwise with repeated scans is the slow path — count memberships instead.
Implement
common_to_all(playlists: list[list[int]]) → list[int]Examples
in
[[[1,2,3],[2,3,4],[3,2,9]]]out[2,3]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 15 min
solution.py
InputExpectedGot
[[[1,2,3],[2,3,4],[3,2,9]]][2,3]not run yetsample