October 24, 2024
Chicago 12, Melborne City, USA
python

How could you come to the intuition that Valid Parentheses on Leetcode requires a stack?


So I’ve solved Valid Parentheses on Leetcode a few times now for space repetition. I totally get the stack solution now, but what I don’t understand is how to come upon the intuition that helps you realize you need a stack data structure. First couple attempts I tried a weird two pointer approach, which I totally understand why it doesn’t work. What are parts of the problem that clue you into the fact you need to use a stack?



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video