Showing:
Handle Score
@Ibrahim Nash 6564
@mb1973 5785
@Quandray 5275
@akhayrutdinov 5111
@saiujwal13083 5074
@kirtidee18 4639
@sanjay05 3762
@mantu_singh 3712
@gfgaccount 3627
@marius_valentin_dragoi 3525
Maximum number of partitions that can be sorted individually to make sorted
Easy Accuracy: 60.28% Submissions: 73 Points: 2

Given an array arr[ ] of size n such that elements of arr[ ] in range [0, 1, ..n-1]. Our task is to divide the array into the maximum number of partitions that can be sorted individually, then concatenated to make the whole array sorted.

Example 1:

â€‹Input : arr[ ] = {2, 1, 0, 3}
Output : 2
Explanation:
If divide arr[] into two partitions
{2, 1, 0} and {3}, sort then and concatenate
then, we get the whole array sorted.


â€‹Example 2:

Input : arr[ ] = {2, 1, 0, 3, 4, 5}
Output :  4 

This is a function problem. The input is already taken care of by the driver code. You only need to complete the function maxPartitions() that takes an array (arr), sizeOfArray (n), and return the maximum number of partitions. The driver code takes care of the printing.

Expected Time Complexity: O(N).
Expected Auxiliary Space: O(1).

Constraints:
1 ≤ T ≤ 100
1 ≤ N ≤ 105