Unit 1 Session 2 (Click for link to problem statements)
Understand what the interviewer is asking for by using test cases and questions about the problem.
Plan the solution with appropriate visualizations and pseudocode.
General Idea: Loop through a list of numbers, and if a number matches the target, add it's index to a results list.
1) Create an empty list to hold the results
2) Loop through the indices of the input list
a) If the element at that index matches the target, add the index to the results list
3) Return the results list
⚠️ Common Mistakes
def find_all_occurrences(lst, target):
indices = []
for i in range(len(lst)):
if lst[i] == target:
indices.append(i)
return indices