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.

agness | 122 |

aman1931998 | 102 |

Survivor | 100 |

uchitnitk | 96 |

lonecoder | 95 |

KshatriyaYash | 1066 |

nikhil_sojan | 1032 |

lonecoder | 1030 |

mazumderrohit8 | 899 |

SumitSingh27 | 832 |

blackshadows | 5327 |

Ibrahim Nash | 5215 |

akhayrutdinov | 5111 |

mb1973 | 4492 |

Quandray | 4444 |

Login to report an issue on this page.