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

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.

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.

_Shubham_Jain_06 | 404 |

maggiiiii | 315 |

Savage_19 | 310 |

ritikdagar0203 | 241 |

thanuvinu94 | 233 |

Bishnu Dev Panda | 810 |

_Shubham_Jain_06 | 715 |

okayboss | 652 |

maggiiiii | 598 |

Savage_19 | 576 |

blackshadows | 5331 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4925 |

Quandray | 4547 |

Login to report an issue on this page.