We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Due to time error, I don't know how to solve this...
#!/bin/python3importmathimportosimportrandomimportreimportsysfromcollectionsimportCounterfromoperatorimportitemgetter## Complete the 'xorSubsequence' function below.## The function is expected to return an INTEGER_ARRAY.# The function accepts LONG_INTEGER_ARRAY a as parameter.#defxor_sub(arr,n):result=[]foriinrange(n):result.append(arr[i])forjinrange(2,n+1):foriinrange(len(arr)-j+1):a=arr[i]forkinrange(1,j):a^=arr[i+k]result.append(a)returnresultdefmaxOccur(A):count=Counter(A)sorted_count=sorted(count.items(),key=lambdax:(-x[1],x[0]))returnsorted_count[0]defxorSubsequence(a):# Write your code herel=[]l=xor_sub(a,len(a))print(l)# check the frequency# a = Counter(l)# a_sorted = sorted(a.items(),key=itemgetter(1), reverse=True)# a_sorted = sorted(a_sorted)ti=maxOccur(l)retL=[]retL.append(ti[0])retL.append(ti[1])returnretLif__name__=='__main__':fptr=open(os.environ['OUTPUT_PATH'],'w')a_count=int(input().strip())a=[]for_inrange(a_count):a_item=int(input().strip())a.append(a_item)result=xorSubsequence(a)fptr.write(' '.join(map(str,result)))fptr.write('\n')fptr.close()
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
XOR Subsequences
You are viewing a single comment's thread. Return to all comments →
Due to time error, I don't know how to solve this...