-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGifts.py
More file actions
36 lines (28 loc) · 711 Bytes
/
Gifts.py
File metadata and controls
36 lines (28 loc) · 711 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# Given an array A of size n, which contains gift ids of various gifts kept in a row. You can select any subarray of gifts that contains all unique gift id.
# What is the longest sequence of successive gifts where each gift id is unique?
test=int(input())
for i in range(test):
n=int(input())
a=list(map(int,input().split()))
start=0
end=0
count=0
num={}
z=[]
while(start<=n):
if a[end] not in num:
num[a[end]]=1
count=count+1
z.append(count)
# if(count>=max):
# max=count
if(end>=n-1):
break
end=end+1
else:
num.pop(a[start],None)
start=start+1
count=count-1
if(end>n):
break
print(max(z))