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.

akhyasharma01 | 467 |

ASWATHAMA | 399 |

john_wick | 360 |

mmzeineddine | 295 |

PiyushPandey4 | 271 |

PiyushPandey4 | 614 |

ASWATHAMA | 561 |

akhyasharma01 | 547 |

john_wick | 521 |

rahulnishad96 | 442 |

blackshadows | 5362 |

Ibrahim Nash | 5242 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4598 |

Login to report an issue on this page.