You are viewing a single comment's thread. Return to all comments →
Java:
//Write your code here public static List dynamicArray(int n, List> queries) { // Write your code here
List<List<Integer>> temp = new ArrayList<>(); List<Integer> sol = new ArrayList<Integer>(); for(int i=0; i<n; i++){ temp.add(new ArrayList<>()); } int lastAnswer = 0; for(List<Integer> query: queries){ int type = query.get(0); int x = query.get(1); int y = query.get(2); int idx = (x ^ lastAnswer) % n; if(type == 1){ temp.get(idx).add(y); } else if(type == 2){ lastAnswer = temp.get(idx).get( y % temp.get(idx).size() ); sol.add(lastAnswer); } } return sol;
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 →
Java:
//Write your code here public static List dynamicArray(int n, List> queries) { // Write your code here