Hacker News new | ask | show | jobs
by braythwayt 2680 days ago
The stack solution checks that the stack is non-empty before popping.

The counter solution simply needs to check that the counter is non-zero before decrementing.

All cases then work perfectly.