{"id":"247ca66a-f2c3-4fb6-a160-49f03140e612","name":"Partition Array Into Disjoint Intervals","description":"1. Given an integer array nums.\r\n2. Partition it into two (contiguous) subarrays left and right so that:\r\n a. Every element in left is less than or equal to every element in right.\r\n b. Left and right are non-empty.\r\n c. Left has the smallest possible size.\r\n3. Return the length of left after such a partitioning.\r\nNOTE : Test cases are generated such that partitioning exists.\r\n","inputFormat":"Input is Managed for You\r\nnums = [5,0,3,8,6]\r\n\r\nnums = [1,1,1,0,6,12]","outputFormat":"3\r\nExplanation: left = [5,0,3], right = [8,6]\r\n\r\n4\r\nExplanation: left = [1,1,1,0], right = [6,12]","constraints":"1. 2 &lt;= nums.length &lt;= 10^5\r\n2. 0 &lt;= nums[i] &lt;= 10^6\r\n3. There is at least one valid answer for the given input.\r\n","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\nusing namespace std;\n\nint partitionDisjoint(vector<int> &arr) {\n //write your code here\n }\n\nint main(){\n int n;\n cin>>n;\n vector<int> arr(n);\n\n for (int i = 0; i < n; i++) {\n cin>>arr[i];\n }\n\n int len = partitionDisjoint(arr);\n cout<<len;\n}"},"java":{"code":"import java.util.*;\r\n\r\npublic class Main {\r\n\r\n // ~~~~~~~~~~~~~~User''s Section~~~~~~~~~~~~~~~\r\n public static int partitionDisjoint(int[] arr) {\r\n // write your code here\r\n }\r\n\r\n // ~~~~~~~~~~~~~Input Management~~~~~~~~~~~~~~~\r\n public static void main(String[] args) {\r\n Scanner scn = new Scanner(System.in);\r\n int n = scn.nextInt();\r\n int[] arr = new int[n];\r\n\r\n for (int i = 0; i < n; i++) {\r\n arr[i] = scn.nextInt();\r\n }\r\n\r\n int len = partitionDisjoint(arr);\r\n System.out.println(len);\r\n }\r\n}"},"python":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"5\r\n5 0 3 8 6","sampleOutput":"3","questionVideo":"","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":"35f2cfb0-6f25-4967-b0c9-92f2384b9260","name":"Arrays And Strings For Intermediate","slug":"arrays-and-strings-for-intermediate-732","type":0},{"id":"0f445d2f-bec3-46fb-8906-498c7d7e5e32","name":"Partition Array Into Disjoint Intervals","slug":"partition-array-into-disjoint-intervals","type":1}],"next":{"id":"f8f27b58-8314-4c07-8c32-72450d67a698","name":"Partition Array Into Disjoint Intervals","type":3,"slug":"partition-array-into-disjoint-intervals"},"prev":{"id":"194db1e4-92e6-4a30-b190-5aa1660c7efa","name":"Partition Labels MCQ","type":0,"slug":"partition-labels-mcq"}}}

Partition Array Into Disjoint Intervals

1. Given an integer array nums. 2. Partition it into two (contiguous) subarrays left and right so that: a. Every element in left is less than or equal to every element in right. b. Left and right are non-empty. c. Left has the smallest possible size. 3. Return the length of left after such a partitioning. NOTE : Test cases are generated such that partitioning exists.

{"id":"247ca66a-f2c3-4fb6-a160-49f03140e612","name":"Partition Array Into Disjoint Intervals","description":"1. Given an integer array nums.\r\n2. Partition it into two (contiguous) subarrays left and right so that:\r\n a. Every element in left is less than or equal to every element in right.\r\n b. Left and right are non-empty.\r\n c. Left has the smallest possible size.\r\n3. Return the length of left after such a partitioning.\r\nNOTE : Test cases are generated such that partitioning exists.\r\n","inputFormat":"Input is Managed for You\r\nnums = [5,0,3,8,6]\r\n\r\nnums = [1,1,1,0,6,12]","outputFormat":"3\r\nExplanation: left = [5,0,3], right = [8,6]\r\n\r\n4\r\nExplanation: left = [1,1,1,0], right = [6,12]","constraints":"1. 2 &lt;= nums.length &lt;= 10^5\r\n2. 0 &lt;= nums[i] &lt;= 10^6\r\n3. There is at least one valid answer for the given input.\r\n","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\nusing namespace std;\n\nint partitionDisjoint(vector<int> &arr) {\n //write your code here\n }\n\nint main(){\n int n;\n cin>>n;\n vector<int> arr(n);\n\n for (int i = 0; i < n; i++) {\n cin>>arr[i];\n }\n\n int len = partitionDisjoint(arr);\n cout<<len;\n}"},"java":{"code":"import java.util.*;\r\n\r\npublic class Main {\r\n\r\n // ~~~~~~~~~~~~~~User''s Section~~~~~~~~~~~~~~~\r\n public static int partitionDisjoint(int[] arr) {\r\n // write your code here\r\n }\r\n\r\n // ~~~~~~~~~~~~~Input Management~~~~~~~~~~~~~~~\r\n public static void main(String[] args) {\r\n Scanner scn = new Scanner(System.in);\r\n int n = scn.nextInt();\r\n int[] arr = new int[n];\r\n\r\n for (int i = 0; i < n; i++) {\r\n arr[i] = scn.nextInt();\r\n }\r\n\r\n int len = partitionDisjoint(arr);\r\n System.out.println(len);\r\n }\r\n}"},"python":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"5\r\n5 0 3 8 6","sampleOutput":"3","questionVideo":"","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":"35f2cfb0-6f25-4967-b0c9-92f2384b9260","name":"Arrays And Strings For Intermediate","slug":"arrays-and-strings-for-intermediate-732","type":0},{"id":"0f445d2f-bec3-46fb-8906-498c7d7e5e32","name":"Partition Array Into Disjoint Intervals","slug":"partition-array-into-disjoint-intervals","type":1}],"next":{"id":"f8f27b58-8314-4c07-8c32-72450d67a698","name":"Partition Array Into Disjoint Intervals","type":3,"slug":"partition-array-into-disjoint-intervals"},"prev":{"id":"194db1e4-92e6-4a30-b190-5aa1660c7efa","name":"Partition Labels MCQ","type":0,"slug":"partition-labels-mcq"}}}
plane

Editor


Loading...

Partition Array Into Disjoint Intervals

medium

1. Given an integer array nums. 2. Partition it into two (contiguous) subarrays left and right so that: a. Every element in left is less than or equal to every element in right. b. Left and right are non-empty. c. Left has the smallest possible size. 3. Return the length of left after such a partitioning. NOTE : Test cases are generated such that partitioning exists.

Constraints

1. 2 <= nums.length <= 10^5 2. 0 <= nums[i] <= 10^6 3. There is at least one valid answer for the given input.

Format

Input

Input is Managed for You nums = [5,0,3,8,6] nums = [1,1,1,0,6,12]

Output

3 Explanation: left = [5,0,3], right = [8,6] 4 Explanation: left = [1,1,1,0], right = [6,12]

Example

Sample Input

5 5 0 3 8 6

Sample Output

3

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode