{"id":"2e366111-c25f-432f-a3e8-bf2bc3f44b1e","name":"132 Pattern","description":"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 < j < k and nums[i] < nums[k] < nums[j].\r\nReturn true if there is a 132 pattern in nums, otherwise, return false.\r\n","inputFormat":"A number n.\r\nn1\r\nn2\r\n.... n numbers","outputFormat":"print true if 132 pattern is found otherwise false.","constraints":"1. n == nums.length\r\n2. 1 &lt;= n &lt;= 10^4\r\n3. -10^9 &lt;= nums[i] &lt;= 10^9","sampleCode":{"cpp":{"code":"#include <bits/stdc++.h>\nusing namespace std;\n\nbool find132pattern(vector<int>& nums) {\n //write your code here\n}\n\nint main()\n{\n\n\n int n;\n cin >> n;\n vector<int>nums(n, 0);\n for (int i = 0; i < n; i++)\n {\n cin >> nums[i];\n }\n int ans = find132pattern(nums);\n if (ans == 1) {\n cout << \"true\" ;\n }\n else {\n cout << \"false\" ;\n }\n return 0;\n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n public static void main(String[] args) throws Exception {\r\n // write your code here\r\n\r\n \r\n }\r\n}\r\n"},"python":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"4\r\n3\r\n1\r\n4\r\n2","sampleOutput":"true\r\n","questionVideo":"https://www.youtube.com/embed/zesp0cWYs4w","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"8c6022a5-8654-4226-918f-8110af738bd4","name":"Stacks For Intermediate","slug":"stacks-for-intermediate-688","type":0},{"id":"5dc2d4c1-f7f7-4ce1-b5fc-09410467ac43","name":"132 Pattern","slug":"132-pattern","type":1}],"next":{"id":"65f60f41-c064-4cba-9ccb-d4259d88ecd8","name":"132 Pattern Medium MCQ","type":0,"slug":"132-pattern-medium-mcq"},"prev":{"id":"8dc63d42-4946-4b5e-9265-1152e7107bcc","name":"Exclusive Time Of Functions","type":3,"slug":"exclusive-time-of-functions"}}}

132 Pattern

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 < j < k and nums[i] < nums[k] < nums[j]. Return true if there is a 132 pattern in nums, otherwise, return false.

{"id":"2e366111-c25f-432f-a3e8-bf2bc3f44b1e","name":"132 Pattern","description":"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 < j < k and nums[i] < nums[k] < nums[j].\r\nReturn true if there is a 132 pattern in nums, otherwise, return false.\r\n","inputFormat":"A number n.\r\nn1\r\nn2\r\n.... n numbers","outputFormat":"print true if 132 pattern is found otherwise false.","constraints":"1. n == nums.length\r\n2. 1 &lt;= n &lt;= 10^4\r\n3. -10^9 &lt;= nums[i] &lt;= 10^9","sampleCode":{"cpp":{"code":"#include <bits/stdc++.h>\nusing namespace std;\n\nbool find132pattern(vector<int>& nums) {\n //write your code here\n}\n\nint main()\n{\n\n\n int n;\n cin >> n;\n vector<int>nums(n, 0);\n for (int i = 0; i < n; i++)\n {\n cin >> nums[i];\n }\n int ans = find132pattern(nums);\n if (ans == 1) {\n cout << \"true\" ;\n }\n else {\n cout << \"false\" ;\n }\n return 0;\n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n public static void main(String[] args) throws Exception {\r\n // write your code here\r\n\r\n \r\n }\r\n}\r\n"},"python":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"4\r\n3\r\n1\r\n4\r\n2","sampleOutput":"true\r\n","questionVideo":"https://www.youtube.com/embed/zesp0cWYs4w","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"8c6022a5-8654-4226-918f-8110af738bd4","name":"Stacks For Intermediate","slug":"stacks-for-intermediate-688","type":0},{"id":"5dc2d4c1-f7f7-4ce1-b5fc-09410467ac43","name":"132 Pattern","slug":"132-pattern","type":1}],"next":{"id":"65f60f41-c064-4cba-9ccb-d4259d88ecd8","name":"132 Pattern Medium MCQ","type":0,"slug":"132-pattern-medium-mcq"},"prev":{"id":"8dc63d42-4946-4b5e-9265-1152e7107bcc","name":"Exclusive Time Of Functions","type":3,"slug":"exclusive-time-of-functions"}}}
plane

Editor


Loading...

132 Pattern

medium

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 < j < k and nums[i] < nums[k] < nums[j]. Return true if there is a 132 pattern in nums, otherwise, return false.

Constraints

1. n == nums.length 2. 1 <= n <= 10^4 3. -10^9 <= nums[i] <= 10^9

Format

Input

A number n. n1 n2 .... n numbers

Output

print true if 132 pattern is found otherwise false.

Example

Sample Input

4 3 1 4 2

Sample Output

true

Question Video

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode