Given an array of n integers. The task is to remove or delete minimum number of elements from the array so that when the remaining elements are placed in the same sequence order form a sorted sequence.

**Input:**

The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. The first line of each test case contains an integer N denoting the size of array A.

The second line of each test case contains N space separated integers denoting elements of the array A[ ].

**Output:**

Output the minimum number of deletions to make a sorted sequence. Print the answer in a new line.

**Constraints:**

1<= T <=100

1<= N <=1000

1<= A[ ] <=1000

**Example:**

**Input:**

1

5

5 6 1 7 4

**Output:**

2

Author: sujnesh

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.

KshatriyaYash | 658 |

RuntimeTerror | 446 |

nikhil_sojan | 388 |

cypherr | 384 |

striver119 | 378 |

KshatriyaYash | 1066 |

nikhil_sojan | 972 |

lonecoder | 909 |

mazumderrohit8 | 864 |

SumitSingh27 | 832 |

blackshadows | 5327 |

Ibrahim Nash | 5215 |

akhayrutdinov | 5111 |

mb1973 | 4462 |

Quandray | 4444 |

Login to report an issue on this page.