Deque sorting
Practice
5 (6 votes)
Sorting
Algorithms
Advanced sorting
Problem
93% Success 628 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code
You are given an array \(A\) of \(N\) distinct integers, your task is to sort the given array using the below operation.
- Choose any element, take it out of the array without changing the order of other elements, and put it back either in front or back.
Your task is to print the minimum number of operations to achieve this.
Input format
- The first line contains an integer denoting the number of test cases \(T\).
- The first line of each test case contains an integer \(N\) denoting the number of elements in array \(A\).
- The second line of each test case contains \(N\) space-separated integers of array \(A\).
Output format
Print \(T\) lines. For each test case:
- Print a single line indicating the minimum number of operations to be performed.
Constraints
\(1 \leq T \leq 20000\)
\(1 \leq N \leq 200000\)
\(1 \leq A_i \leq 10^9 \forall i \in [1,N]\)
All \(A_i\) are distinct.
The sum of N over all test cases does not exceed 200000.
Submissions
Please login to view your submissions
Similar Problems
Points:30
1 votes
Tags:
MediumArraysSortingAlgorithmsSetSorting
Points:30
2 votes
Tags:
AlgorithmsSortingAdvanced Sorting
Points:30
6 votes
Tags:
SortingAlgorithmsAdvanced Sorting
Editorial