Back to course home
0% completed
Vote For New Content
132 Pattern (medium)
Problem Statement
Given an array nums
, containing N
integers.
A 132 pattern
consists of three numbers, say x, y, and z, where x < z
and z < y
. This is often referred to as a '132' pattern because if we represent x, y, and z as 1, 3, and 2, respectively, it mimics the positional pattern in '132'.
Return true
if such a pattern exists within any sequence of given numbers nums
. Otherwise, return false
.
Examples
-
Example 1:
- Input: nums = [3, 5, 0, 3, 4]
- Expected Output: True
- Justification: Here, 3 < 4 and 4 < 5, forming a '132' pattern with the numbers 3, 5, and 4.
-
Example 2:
- Input: nums = [1, 2, 3, 4]
- Expected Output: False
- Justification: The sequence is in ascending order, and no '132' pattern is present.
-
Example 3:
- Input: nums = [9, 11, 8, 9, 10, 7, 9]
- Expected Output: True
- Justification: The pattern is formed with 8 < 9 and 9 < 10 in sequence 8, 10, 9.
Constraints:
n == nums.length
- 1 <= n <= 2 * 10<sup>5</sup>
- -10<sup>9</sup> <= nums[i] <= 10<sup>9</sup>
Try it yourself
Try solving this question here:
Python3
Python3
. . . .
.....
.....
.....
Like the course? Get enrolled and start learning!
Table of Contents
Contents are not accessible
Contents are not accessible
Contents are not accessible
Contents are not accessible
Contents are not accessible