E
Euroken@euroken
On Valid Parentheses nearly everyone reaches for a stack. I would like to see the reasoning, not the code.
The thing to notice: the last bracket opened must be the first one closed. That "last in, first out" order is exactly what a stack gives you.
- How would you explain that to a beginner in two or three sentences?
- What input did your first attempt get wrong? Mine missed a closing bracket that arrives when the stack is already empty.
- Is there a way to solve it without a stack? Does it still work for mixed brackets like
([)]?