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.

bruceewayne | 119 |

rajupraaa1234 | 110 |

SUZAKU | 104 |

yash_sharan | 104 |

Core_Ka_Bachha | 99 |

mr_kksparrow | 433 |

manvirag982 | 302 |

rajupraaa1234 | 245 |

Exception_404 | 244 |

snow_den_ | 236 |

blackshadows | 5331 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4567 |

Login to report an issue on this page.