{"id":"2bf274d7-0f7f-477f-a95f-ff829b56e887","name":"Max Chunks To Make Array Sorted 2","description":"1. Given an array arr of integers (not necessarily distinct).\r\n2. We split the array into some number of \"chunks\" (partitions), and individually sort each chunk. \r\n3. After concatenating them, the result equals the sorted array.\r\n4. What is the most number of chunks we could have made?\r\n","inputFormat":"arr = [2,1,3,4,4]\r\n","outputFormat":"4\r\nExplanation:\r\nWe can split into two chunks, such as [2, 1], [3, 4, 4].\r\nHowever, splitting into [2, 1], [3], [4], [4] is the highest number of chunks possible.\r\n","constraints":"1. arr will have length in range [1, 2000].\r\n2. arr[i] will be an integer in range [0, 10^8].\r\n","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\nusing namespace std;\n\nint maxChunksToSorted2(vector<int> &arr) {\n \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 res = maxChunksToSorted2(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 maxChunksToSorted2(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 = maxChunksToSorted2(arr);\r\n System.out.println(res);\r\n }\r\n}"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"8\r\n4 3 6 5 7 12 11 10","sampleOutput":"4","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":"16dc1196-9e9c-41fc-9fca-d093dc0567d1","name":"Max Chunks To Make Array Sorted 2","slug":"max-chunks-to-make-array-sorted-2","type":1}],"next":{"id":"035af625-2c78-4eea-a51b-34c74de68d46","name":"Max Chunks To Make Array Sorted 2","type":3,"slug":"max-chunks-to-make-array-sorted-2"},"prev":{"id":"2b3bac5b-1f23-42cd-a722-4ee1be2a25b4","name":"Max Chunks To Make Array Sorted MCQ","type":0,"slug":"max-chunks-to-make-array-sorted-mcq"}}}

Max Chunks To Make Array Sorted 2

1. Given an array arr of integers (not necessarily distinct). 2. We split the array into some number of "chunks" (partitions), and individually sort each chunk. 3. After concatenating them, the result equals the sorted array. 4. What is the most number of chunks we could have made?

{"id":"2bf274d7-0f7f-477f-a95f-ff829b56e887","name":"Max Chunks To Make Array Sorted 2","description":"1. Given an array arr of integers (not necessarily distinct).\r\n2. We split the array into some number of \"chunks\" (partitions), and individually sort each chunk. \r\n3. After concatenating them, the result equals the sorted array.\r\n4. What is the most number of chunks we could have made?\r\n","inputFormat":"arr = [2,1,3,4,4]\r\n","outputFormat":"4\r\nExplanation:\r\nWe can split into two chunks, such as [2, 1], [3, 4, 4].\r\nHowever, splitting into [2, 1], [3], [4], [4] is the highest number of chunks possible.\r\n","constraints":"1. arr will have length in range [1, 2000].\r\n2. arr[i] will be an integer in range [0, 10^8].\r\n","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\nusing namespace std;\n\nint maxChunksToSorted2(vector<int> &arr) {\n \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 res = maxChunksToSorted2(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 maxChunksToSorted2(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 = maxChunksToSorted2(arr);\r\n System.out.println(res);\r\n }\r\n}"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"8\r\n4 3 6 5 7 12 11 10","sampleOutput":"4","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":"16dc1196-9e9c-41fc-9fca-d093dc0567d1","name":"Max Chunks To Make Array Sorted 2","slug":"max-chunks-to-make-array-sorted-2","type":1}],"next":{"id":"035af625-2c78-4eea-a51b-34c74de68d46","name":"Max Chunks To Make Array Sorted 2","type":3,"slug":"max-chunks-to-make-array-sorted-2"},"prev":{"id":"2b3bac5b-1f23-42cd-a722-4ee1be2a25b4","name":"Max Chunks To Make Array Sorted MCQ","type":0,"slug":"max-chunks-to-make-array-sorted-mcq"}}}
plane

Editor


Loading...

Max Chunks To Make Array Sorted 2

easy

1. Given an array arr of integers (not necessarily distinct). 2. We split the array into some number of "chunks" (partitions), and individually sort each chunk. 3. After concatenating them, the result equals the sorted array. 4. What is the most number of chunks we could have made?

Constraints

1. arr will have length in range [1, 2000]. 2. arr[i] will be an integer in range [0, 10^8].

Format

Input

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

Output

4 Explanation: We can split into two chunks, such as [2, 1], [3, 4, 4]. However, splitting into [2, 1], [3], [4], [4] is the highest number of chunks possible.

Example

Sample Input

8 4 3 6 5 7 12 11 10

Sample Output

4

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode