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.
Solution in Python3. The wording is initially very confusing but just try to follow the instructions given.
#!/bin/python3importmathimportosimportrandomimportreimportsys## Complete the 'dynamicArray' function below.## The function is expected to return an INTEGER_ARRAY.# The function accepts following parameters:# 1. INTEGER n# 2. 2D_INTEGER_ARRAY queries#defdynamicArray(n,queries):# Write your code herelastAnswer=0results=[]arr=[[]for_inrange(n)]forqueryinqueries:ifquery[0]==1:idx=(query[1]^lastAnswer)%narr[idx].append(query[2])ifquery[0]==2:idx=(query[1]^lastAnswer)%nlastAnswer=arr[idx][query[2]%len(arr[idx])]results.append(lastAnswer)returnresultsif__name__=='__main__':fptr=open(os.environ['OUTPUT_PATH'],'w')first_multiple_input=input().rstrip().split()n=int(first_multiple_input[0])q=int(first_multiple_input[1])queries=[]for_inrange(q):queries.append(list(map(int,input().rstrip().split())))result=dynamicArray(n,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
Dynamic Array
You are viewing a single comment's thread. Return to all comments →
Solution in Python3. The wording is initially very confusing but just try to follow the instructions given.