Problem: https://www.codechef.com/COOK118B/problems/CHEFRECP
My code: https://www.codechef.com/viewsolution/33304957
Please can someone point out my mistake? My approach is first I check for contiguous subarray using bool type visited array & then check for distinct frequency using map. Its showing correct output for given test cases but not accepted.
Consider this case:
1
3
1000 500 500
Your are declearing the vis array with number of disticnt element in the input but accesing the values of the array. For this case, vis array has size 2 but you accessing vis[1000] and vis[500].
1 Like
My code is giving “YES” for this. There are 3 elements that you’ve passed in the input of array.
Oops sorry bro, i got my mistake now. Such a stupid mistake I’ve done. Thankyouuu .
1 Like
Updated.
Please tell me where i am wrong
from itertools import groupby
for i in range(int(input())):
n = int(input())
c = 0
a = list(map(int, input().split()))
g = sorted(a)
b = [len(list(group)) for key, group in groupby(a)]
h = [len(list(group)) for key, group in groupby(g)]
b = sorted(b)
h = sorted(h)
#print(b)
#print(h)
if(b == h):
#print(b)
#b = sorted(b)
d = [len(list(group)) for key, group in groupby(b)]
#for i in range(len(b)-1):
# if(b[i] == b[i+1]):
# c = 0
# else:
# c = 1
for i in d:
if(i > 1):
c = 1
#print(c)
if(c == 1):
print("NO")
else:
print("YES")
else:
print("NO")