You are viewing a single comment's thread. Return to all comments →
public static List<Integer> dynamicArray(int n, List<List<Integer>> queries) { List<List<Integer>> result = new ArrayList<>(n); List<Integer> store = new ArrayList<>(); for (int i = 0; i < n; i++) { result.add(new ArrayList<>()); } int lastAnswer = 0; for (List<Integer> query : queries) { int index = (query.get(1) ^ lastAnswer) % n; switch (query.get(0)) { case 1: result.get(index).add(query.get(2)); break; case 2: int indey = query.get(2) % result.get(index).size(); lastAnswer = result.get(index).get(indey); store.add(lastAnswer); break; } } return store; }
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 →