# Hints for DEQUEUE

Someone please give some hints related to DEQUEUE

Try to think about something like circular window.

I tried using the below code but it gave wrong answers can someone explain

for _ in range(int(input())):
n,m = map(int,input().split())
arr = list(map(int,input().split()))
mySet = {i for i in range(1,n+1)}
def solve(arr,Set,popped):
if Set == mySet:
return popped
element1 = arr
element2 = arr[-1]
Set1 = Set.union({element1})
Set2 = Set.union({element2})
return min(solve(arr[1:],Set1,popped+1),
solve(arr[:-1],Set2,popped+1))
S = set()
result = solve(arr,S,0)
print(result)

1 Like

Try to find out the maximum size of contiguous sub-array & by removing it from array still we have all the elements ranges from [1, N].

using simple sliding window technique

``````signed main () {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int test = 1;
cin >> test;
while (test--) {
int n, m;
cin >> n >> m;
vector<int>nums(m) ;
for (int& in : nums)	cin >> in ;
map<int,int>umap ;
for (int in : nums) {
umap[in]++ ;
}
int leave = 0;
for (int i=0, j=0; i<m; ++i) {
if (--umap[nums[i]] == 0)	umap.erase(nums[i]) ;

while (j<m && int(umap.size()) < n) {
umap[nums[j]]++ ;
j++ ;
}
leave = max(leave, i-j+1) ;
}
cout << m - leave << "\n" ;
}

return 0;
}
``````

Here is my solution: `https://www.codechef.com/viewsolution/47098847`