Question
Given a list of integers that may contain repeats, produce a new list that keeps only the last occurrence of each distinct value, with the survivors appearing in the same relative order they hold in the original list. For example, [1, 2, 1, 3, 2] keeps the 1 at index 2, the 3 at index 3, and the 2 at index 4, so the answer is [1, 3, 2]. Note this is not the same as keeping first occurrences and cannot be solved by a single forward filter without preparation.
keep_last_occurrences(nums: list[int]) → list[int][[1,2,1,3,2]]out[1,3,2]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.
Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.