First play index
A listening-history service wants a quick lookup of when each song first appeared in a session. Given the session play log — a list of song ids in play order — return a dictionary that maps every distinct song id to the zero-based index of its first play. Later plays never change the stored index. For example, ["a", "b", "a", "c"] returns {"a": 0, "b": 1, "c": 3}: the second "a" at index 2 is ignored because "a" was first played at index 0.
Implement
first_play_index(plays: list[str]) → dict[str,int]Examples
in
[["a","b","a","c"]]out{"a":0,"b":1,"c":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 10 min
solution.py
InputExpectedGot
[["a","b","a","c"]]{"a":0,"b":1,"c":3}not run yetsample