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.
#!/bin/python3importmathimportosimportrandomimportreimportsys## Complete the 'xorKey' function below.## The function is expected to return a LONG_INTEGER_ARRAY.# The function accepts following parameters:# 1. LONG_INTEGER_ARRAY x# 2. 2D_LONG_INTEGER_ARRAY queries#defxorKey(x,queries):res=[]foriinqueries:maxi=0a,l,r=i[0],i[1],i[2]ifl==r:maxi=a^x[l-1]else:forjinrange(l,r+1):ifj<len(x):xori=a^x[j-1]ifxori>=maxi:maxi=xorires.append(maxi)returnresif__name__=='__main__':fptr=open(os.environ['OUTPUT_PATH'],'w')t=int(input().strip())fort_itrinrange(t):first_multiple_input=input().rstrip().split()n=int(first_multiple_input[0])q=int(first_multiple_input[1])x=list(map(int,input().rstrip().split()))queries=[]for_inrange(q):queries.append(list(map(int,input().rstrip().split())))result=xorKey(x,queries)fptr.write('\n'.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 key
You are viewing a single comment's thread. Return to all comments →