614. 132 Pattern

MediumStackMonotonic StackStack

Given an array nums, determine whether there exists a 132 pattern: indices i < j < k with nums[i] < nums[k] < nums[j]. Return true or false. The input is JSON {nums}.

Input: JSON {nums}.

Output: Boolean — true or false.

Examples

Example 1
Input: {"nums":[3,1,4,2]}
Output: true
Explanation: 1 < 2 < 4 forms the pattern.
Example 2
Input: {"nums":[1,2,3,4]}
Output: false
Explanation: No such triple.
Example 3
Input: {"nums":[-1,3,2,0]}
Output: true
Explanation: -1 < 0 < 3.

Constraints

Asked by

AmazonBloombergGoogleMetaMicrosoft
Solve this problem in the editor →