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: Find items unique to one list, and categorize based on which list they were unique to.
1) Create an empty dict for unique
2) For each item in list_a:
a) If item is not in list_b, map item -> True in unique dict
3) For each item in list_b:
a) If item is not in list_a, map item -> False in unique dict
4) Return unique dict
I-mplement
deffind_unique_items(list_a, list_b):
unique= {} # Initialize an empty dictionary to store unique items and their origin (True for list_a, False for list_b)# Check for items in list_a not in list_bforiteminlist_a:
ifitemnotinlist_b:
unique[item] =True# Check for items in list_b not in list_aforiteminlist_b:
ifitemnotinlist_a:
unique[item] =Falsereturnunique