{"id":"bf6ed7fc-86b9-48f7-9219-adf1dc6854ce","name":"Max Chunks To Make Array Sorted","description":"1. Given an array arr that is a permutation of [0, 1, ..., arr.length - 1].\r\n2. We split the array into some number of \"chunks\" (partitions), and individually sort each chunk. \r\n3. Shuffling of chunk is not allowed.\r\n4. After concatenating them, the result equals the sorted array.\r\n5. What is the most number of chunks we could have made?\r\n","inputFormat":"arr = [4,3,2,1,0]\r\n","outputFormat":"1\r\nExplanation:\r\nSplitting into two or more chunks will not return the required result.\r\nFor example, splitting into [4, 3], [2, 1, 0] will result in [3, 4, 0, 1, 2], which isn't sorted.","constraints":"1. arr will have length in range [1, 10].\r\n2. arr[i] will be a permutation of [0, 1, ..., arr.length - 1].\r\n","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\nusing namespace std;\n\nint maxChunksToSorted(vector<int> &arr) {\n //write your code here\n \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 res = maxChunksToSorted(arr);\n cout<<res;\n}"},"java":{"code":"import java.util.*;\r\n\r\npublic class Main {\r\n\r\n // ~~~~~~~~~~~~~~~User Section~~~~~~~~~~~~~~~~~~\r\n public static int maxChunksToSorted(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 res = maxChunksToSorted(arr);\r\n System.out.println(res);\r\n }\r\n}"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"6\r\n2 0 1 3 5 4","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":"62eb58d3-bb5c-411d-8ea9-1737376fddad","name":"Max Chunks To Make Array Sorted","slug":"max-chunks-to-make-array-sorted","type":1}],"next":{"id":"e1e17f39-51d3-4a2e-bd30-3437c763bbb4","name":"Max Chunks To Make Array Sorted","type":3,"slug":"max-chunks-to-make-array-sorted"},"prev":{"id":"9d03901b-dfe4-4bb4-8fb6-20ab0a8ec70e","name":"Majority Elements II MCQ","type":0,"slug":"majority-elements-ii-mcq"}}}

Max Chunks To Make Array Sorted

1. Given an array arr that is a permutation of [0, 1, ..., arr.length - 1]. 2. We split the array into some number of "chunks" (partitions), and individually sort each chunk. 3. Shuffling of chunk is not allowed. 4. After concatenating them, the result equals the sorted array. 5. What is the most number of chunks we could have made?

{"id":"bf6ed7fc-86b9-48f7-9219-adf1dc6854ce","name":"Max Chunks To Make Array Sorted","description":"1. Given an array arr that is a permutation of [0, 1, ..., arr.length - 1].\r\n2. We split the array into some number of \"chunks\" (partitions), and individually sort each chunk. \r\n3. Shuffling of chunk is not allowed.\r\n4. After concatenating them, the result equals the sorted array.\r\n5. What is the most number of chunks we could have made?\r\n","inputFormat":"arr = [4,3,2,1,0]\r\n","outputFormat":"1\r\nExplanation:\r\nSplitting into two or more chunks will not return the required result.\r\nFor example, splitting into [4, 3], [2, 1, 0] will result in [3, 4, 0, 1, 2], which isn't sorted.","constraints":"1. arr will have length in range [1, 10].\r\n2. arr[i] will be a permutation of [0, 1, ..., arr.length - 1].\r\n","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\nusing namespace std;\n\nint maxChunksToSorted(vector<int> &arr) {\n //write your code here\n \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 res = maxChunksToSorted(arr);\n cout<<res;\n}"},"java":{"code":"import java.util.*;\r\n\r\npublic class Main {\r\n\r\n // ~~~~~~~~~~~~~~~User Section~~~~~~~~~~~~~~~~~~\r\n public static int maxChunksToSorted(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 res = maxChunksToSorted(arr);\r\n System.out.println(res);\r\n }\r\n}"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"6\r\n2 0 1 3 5 4","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":"62eb58d3-bb5c-411d-8ea9-1737376fddad","name":"Max Chunks To Make Array Sorted","slug":"max-chunks-to-make-array-sorted","type":1}],"next":{"id":"e1e17f39-51d3-4a2e-bd30-3437c763bbb4","name":"Max Chunks To Make Array Sorted","type":3,"slug":"max-chunks-to-make-array-sorted"},"prev":{"id":"9d03901b-dfe4-4bb4-8fb6-20ab0a8ec70e","name":"Majority Elements II MCQ","type":0,"slug":"majority-elements-ii-mcq"}}}
plane

Editor


Loading...

Max Chunks To Make Array Sorted

easy

1. Given an array arr that is a permutation of [0, 1, ..., arr.length - 1]. 2. We split the array into some number of "chunks" (partitions), and individually sort each chunk. 3. Shuffling of chunk is not allowed. 4. After concatenating them, the result equals the sorted array. 5. What is the most number of chunks we could have made?

Constraints

1. arr will have length in range [1, 10]. 2. arr[i] will be a permutation of [0, 1, ..., arr.length - 1].

Format

Input

arr = [4,3,2,1,0]

Output

1 Explanation: Splitting into two or more chunks will not return the required result. For example, splitting into [4, 3], [2, 1, 0] will result in [3, 4, 0, 1, 2], which isn't sorted.

Example

Sample Input

6 2 0 1 3 5 4

Sample Output

3

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode