Given an array of **n** elements. Make strictly increasing and strictly decreasing subsequences from the array such that each array element belongs to increasing subsequence or decreasing subsequence, but not both, or can be part of none of the subsequence. Minimize the number of elements which are not part of any of the subsequences and find the count of such elements.

**Input:**

First line consists of T test cases. First line of every test case consists of N, denoting the number of elements of array. Second line of every test case consists of elements of array.

**Output:**

Single line output i.e minimum number of element which is not part of increasing or decreasing subsequence in the array.

**Constraints:**

1<=T<=100

1<= N <=100

1 <= arr[i] <= 100

**Example:
Input :**

1

12

7 8 1 2 4 6 3 5 2 1 8 7

2

**Explanation:**

Increasing sequence can be { 1, 2, 4, 5, 8 }. Decreasing sequence can be { 7, 6, 3, 2, 1 }. So, only 2 (8, 7) element is left which are not part of either of the subsequences.

Author: anuj0503

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.

jhasaurabh312 | 138 |

Aaaaarohiiii | 136 |

Harsha_kunchala | 128 |

tushki | 124 |

RajaRajput | 117 |

ARUN_PUNDIR | 617 |

manishgupta8497 | 607 |

Abhimanyu_kumar | 559 |

KhyatiSoneji | 501 |

Aman___Jain | 496 |

blackshadows | 5335 |

Ibrahim Nash | 5223 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4567 |

Login to report an issue on this page.