You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Understand what the interviewer is asking for by using test cases and questions about the problem.
P-lan
Plan the solution with appropriate visualizations and pseudocode.
General Idea: Loop backwards through the list, and each time we find a new element, add it to the front of a new list.
1) Create an empty list to store unique numbers
2) Starting at the END of the nums list:
a) If the number is not already in unique,
insert it at the beginning of unique
3) Return the unique nums
Alternate solution using a modified frequency map:
defremove_duplicates_from_front(nums):
frequency_map= {}
fornuminnums:
frequency_map[num] =Truelast_occurrences= []
fornuminnums[::-1]: # Reverse iterateiffrequency_map[num]:
last_occurrences.append(num)
frequency_map[num] =Falsereturnlast_occurrences[::-1] # Reverse again to original order