Given an array nums, determine whether there exists a subsequence of three integers nums[i], nums[j], nums[k] such that i < j < k and nums[i] < nums[k] < nums[j]. Example: Input: nums = [3,1,4,2] Output: true Explanation: The subsequence (1, 4, 2) satisfies the 132 pattern. Pattern focus: Monotonic Stack for pattern detection.
nums = array of integers
true if a 132 pattern exists; otherwise false
Example 1:
Input:
nums = [3,1,4,2]
Output:
true
Explanation:
The subsequence 1,4,2 matches the required ordering.
Example 2:
Input:
nums = [1,2,3,4]
Output:
false
Explanation:
No subsequence can satisfy nums[i] < nums[k] < nums[j].