← 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
Hiring now
Software engineer roles are open right now
landed applies to roles like these for you, on each company’s own site, with answers written for the role.
Get 5x interviews10 free auto-applies. No card.

Senior Software Engineer -.NET
Tyler Technologies · Annapolis, Maryland

Software Development Engineer II
SaaS Labs · Bengaluru, Karnataka, India

Advanced Software Engineer - Product Architect (Legal, Safety, and Risk)
Metropolitan Transportation Authority · New York, NY
Next question