forked from codepath/compsci_guides
-
Notifications
You must be signed in to change notification settings - Fork 0
Delete Minimum
Jessica Sang edited this page Sep 14, 2024
·
1 revision
Unit 3 Session 2 (Click for link to problem statements)
- 💡 Difficulty: Easy
- ⏰ Time to complete: 10-15 mins
- 🛠️ Topics: List manipulation, Iteration, Finding minimum element, Removing elements
Understand what the interviewer is asking for by using test cases and questions about the problem.
- What if there are duplicate elements?
- Duplicates can be removed in any order.
Plan the solution with appropriate visualizations and pseudocode.
General Idea: While there is still something in the original list, find the smallest value and remove it.
1) Create an empty list for removal order
2) While the input list is not empty:
a) Find the minimum element
b) Remove it from the input list
c) Add it to the removal list
3) Return the removal list
def delete_minimum_elements(nums):
removed_order = []
while nums:
min_val = min(nums)
nums.remove(min_val)
removed_order.append(min_val)
return removed_order