132 Pattern LeetCode solution in JavaScript
1var find132pattern = function (nums) {2let m = -Infinity;3// Initialise a empty stack...4const stack = [];5// Run a Loop from last to first index...6for (let i = nums.length - 1; i >= 0; i--) {7// If nums[i] is greater than the top element of stack, then pop the element...8while (nums[i] > stack[stack.length - 1]) {9m = stack.pop();10}11// If m is greater than nums[i], return true...12if (nums[i] < m) {13return true;14}15// Otherwise, push nums[i] into stack...16stack.push(nums[i]);17}18// If the condition is not satisfied, return false.19return false;20};