Maximum number of partitions that can be sorted individually to make sorted
Submissions: 1076   Accuracy:

25.81%

  Difficulty: Easy   Marks: 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.

Input:
The first line of the input contains an integer T, the number of test cases. For each test case, the first line contains an integer n, denoting the size of the array
arr. Next line contains n- space separated integers denoting the elements of the array arr.

Output:
For each test case, the output is an integer displaying the maximum number of partitions.

Constraints:
1<=T<=100
1<=n<=25

Example:
Input:

2
4
2 1 0 3
6
2 1 0 3 4 5
Output:
2
4

Explanation:
1. 
If divide arr[] into two partitions {2, 1, 0} and {3}, sort then and concatenate then, we get the whole array sorted.
2. The maximum number of partitions are four, we get these partitions as {2, 1, 0}, {3}, {4} and {5}

 

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Vanshika
Author: Vanshika_pec


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.