132 Pattern
Given an array of n integers nums, a 132 pattern is a subsequence of three indices i < j < k such that nums[i] < nums[k] < nums[j]. Return true if there is a 132 pattern in nums, otherwise return false.
Open official problem prompt ↗Decide whether some triple of positions forms the shape low, then highest, then a middle value strictly between them.
Reading a stock chart backwards, you remember the highest peak you have passed and the best 'pullback' price just below a peak. If you ever reach an earlier price below that pullback, the up-then-partway-down pattern is confirmed.
- Input
- nums = [3, 1, 4, 2]
- Output
- true
- Why
- Indices i=1, j=2, k=3 give nums[i]=1 < nums[k]=2 < nums[j]=4, matching the 1-3-2 shape.
n == nums.length1 <= n <= 2 * 10^5-10^9 <= nums[i] <= 10^9