← All questions
MediumCoding
132 Pattern
Asked at
Intuit
1Give yourself 5 minutes
2Answer out loud, not in your head
3Then compare with the answer below
0
Stuck? Show a way to structure it+
- 01State the target: find indices i < j < k with nums[i] < nums[k] < nums[j].
- 02Scan from right to left, maintaining a decreasing stack of possible middle values nums[j].
- 03Track a separate variable ak: the best valid third value popped from the stack so far.
- 04Before pushing the current value, return true if it is smaller than ak.
- 05Pop every smaller stack value into ak, then push the current value and explain the invariant.
Reference answer
Then expect these follow-ups
Why must the traversal be right to left for this invariant?
Tests: invariant reasoning
How would you return the actual three indices rather than a boolean?
Tests: state reconstruction
Free to read · better with Enzo
Practice this out loud with Enzo
Enzo runs it as a mock interview, pushes back with follow-ups, and grades you on the rubric.
Next question