Skip to content
Decoder

132 Pattern

Medium

Problem

A 132 pattern in a list nums is three positions i < j < k with nums[i] < nums[k] < nums[j]: a small value, then a big one, then one in between (like the digits 1, 3, 2). Return true if nums contains a 132 pattern, otherwise false. The three values do not have to be next to each other.

Example 1

Input
nums = [1, 2, 3, 4]
Output
false

Example 2

Input
nums = [3, 1, 4, 2]
Output
true
Why
1, 4, 2

Example 3

Input
nums = [-1, 3, 2, 0]
Output
true
Why
-1, 3, 2

Constraints

  • n == nums.length
  • 1 <= n <= 2 * 10^5
  • -10^9 <= nums[i] <= 10^9

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.