Given an array of n integers nums, a 132 pattern is a subsequence of three integers nums[i], nums[j] and nums[k] such that i &lt; j &lt; k and nums[i] &lt; nums[k] &lt; nums[j].

Return true if there is a 132 pattern in nums, otherwise, return false.

&nbsp;
Example 1:

Input: nums = [1,2,3,4]
Output: false
Explanation: There is no 132 pattern in the sequence.


Example 2:

Input: nums = [3,1,4,2]
Output: true
Explanation: There is a 132 pattern in the sequence: [1, 4, 2].


Example 3:

Input: nums = [-1,3,2,0]
Output: true
Explanation: There are three 132 patterns in the sequence: [-1, 3, 2], [-1, 3, 0] and [-1, 2, 0].


&nbsp;
Constraints:


	n == nums.length
	1 &lt;= n &lt;= 2 * 105
	-109 &lt;= nums[i] &lt;= 109


class Solution(object):
    def find132pattern(self, nums):
        # Base Condition...
        if len(nums) < 3:
            return False
        m = float('-inf')
        # Initialise a empty stack...
        stack = []
        # Run a Loop from last to first index...
        for i in range(len(nums)-1, -1, -1):
            # If m is greater than nums[i], return true...
            if nums[i] < m:
                return True
            # If stack is not empty &  nums[i] is greater than the top element of stack, then pop the element...
            else:
                while stack and stack[-1] < nums[i]:
                    m = stack.pop()
            # Otherwise, append nums[i] into stack...
            stack.append(nums[i])
        # If the condition is not satisfied, return false.
        return False
class Solution {
    public boolean find132pattern(int[] nums) {
        int min = Integer.MIN_VALUE;
        int peak = nums.length;
        for (int i = nums.length - 1; i >= 0; i--) {
            // We find a "132" pattern if nums[i] < min, so return true...
            if (nums[i] < min)
                return true;
            // If peak < nums.length & nums[i] is greater than the peak element...
            while (peak < nums.length && nums[i] > nums[peak])
                min = nums[peak++];
            // Now we have nums[i] <= nums[peak]
            // We push nums[i] to the "stack"
            peak--;
            nums[peak] = nums[i];
        }
        return false;
    }
}
class Solution {
public:
    bool find132pattern(vector<int>& nums) {
        // Initialise a empty stack "s"...
        stack<int> s;
        // To keep track of minimum element...
        int min = INT_MIN;
        // Run a Loop from last to first index...
        for (int i = nums.size() - 1; i >= 0; i--) {
            // If min is greater than nums[i], return true...
            if (nums[i] < min)
                return true;
            // If stack is not empty &  nums[i] is greater than the top element of stack, then pop the element...
            while (!s.empty() && nums[i] > s.top()) {
                min = s.top();
                s.pop();
            }
            // Otherwise, push nums[i] into stack...
            s.push(nums[i]);
        }
        // If the condition is not satisfied, return false.
        return false;
    }
};
var find132pattern = function(nums) {
    let m = -Infinity
    // Initialise a empty stack...
    const stack = []
    // Run a Loop from last to first index...
    for (let i = nums.length - 1; i >= 0; i--) {
        // If nums[i] is greater than the top element of stack, then pop the element...
        while (nums[i] > stack[stack.length - 1]) {
            m = stack.pop()
        }
        // If m is greater than nums[i], return true...
        if (nums[i] < m) {
            return true
        }
        // Otherwise, push nums[i] into stack...
        stack.push(nums[i])
    }
    // If the condition is not satisfied, return false.
    return false
};
132 Pattern