Question DSA-STK-0014
MediumHow can a stack support getMin() in O(1)?
- A.
Keep a second stack holding the current minimum after each push
- B.
Scan the stack each time
- C.
Sign up free to see the answer and a step-by-step explanation.
Popular companies
Prepare company by company
Hiring pattern, syllabus, past questions and mocks for each company.
All companiesPractice by subject
Stacks question
How can a stack support getMin() in O(1)?
Keep a second stack holding the current minimum after each push
Scan the stack each time
Sign up free to see the answer and a step-by-step explanation.
Sort the stack after each push
Use a queue instead