HackerRank Dynamic Array Solution in Python YASH PAL, May 21, 2025May 21, 2025 Today we are going to solve HackerRank Dynamic Array problem solution in python programming. we need to declare a 2 dimensional array with empty array all zero indexed and then we need to declare an integer variable and then need to initialize it to 0. after that we need to process two types of queries. we need to complete the dynamic array function that has a input denotes the number of empty arrays to initialize in array and the queries in 2D array of integers. Dynamic array Dynamic array problem solution in Python3 N, Q = input().strip().split(‘ ‘) N, Q = int(N), int(Q) seq = [[] for i in range(N)] lastans = 0 #print(N, Q, lastans, seq) for q in range(Q): t, x, y = input().strip().split(‘ ‘) t, x, y = int(t), int(x), int(y) x = (x^lastans) % N if t == 1: seq[x].append(y) else: y = y % len(seq[x]) print(seq[x][y]) lastans = seq[x][y] #print(x, seq[x])N, Q = input().strip().split(' ') N, Q = int(N), int(Q) seq = [[] for i in range(N)] lastans = 0 #print(N, Q, lastans, seq) for q in range(Q): t, x, y = input().strip().split(' ') t, x, y = int(t), int(x), int(y) x = (x^lastans) % N if t == 1: seq[x].append(y) else: y = y % len(seq[x]) print(seq[x][y]) lastans = seq[x][y] #print(x, seq[x]) Problem solution in Python 2 # Enter your code here. Read input from STDIN. Print output to STDOUT n, q = map(int, raw_input().split()) arrs = [] for _ in range(n): arrs.append([]) lastans = 0 for _ in range(q): _type, x, y = map(int, raw_input().split()) if _type == 1: arrs[(x ^ lastans) % n].append(y) elif _type == 2: arr_i = (x ^ lastans) % n size = len(arrs[arr_i]) lastans = arrs[arr_i][y % size] print lastans# Enter your code here. Read input from STDIN. Print output to STDOUT n, q = map(int, raw_input().split()) arrs = [] for _ in range(n): arrs.append([]) lastans = 0 for _ in range(q): _type, x, y = map(int, raw_input().split()) if _type == 1: arrs[(x ^ lastans) % n].append(y) elif _type == 2: arr_i = (x ^ lastans) % n size = len(arrs[arr_i]) lastans = arrs[arr_i][y % size] print lastans array DS problems arraysDSA