← All questions
MediumCoding

132 Pattern

Asked atIntuit
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+
  1. 01State the target: find indices i < j < k with nums[i] < nums[k] < nums[j].
  2. 02Scan from right to left, maintaining a decreasing stack of possible middle values nums[j].
  3. 03Track a separate variable ak: the best valid third value popped from the stack so far.
  4. 04Before pushing the current value, return true if it is smaller than ak.
  5. 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

Or practice this question first

Next question