dsa
1 til · all topics
20261 til
a single curr_min variable forgets the previous minimum the moment you pop. storing (val, min_so_far) with every entry keeps push, pop and getMin all O(1) — and makes pop rewind the minimum for free.
1 til · all topics
a single curr_min variable forgets the previous minimum the moment you pop. storing (val, min_so_far) with every entry keeps push, pop and getMin all O(1) — and makes pop rewind the minimum for free.