You are viewing a single comment's thread. Return to all comments →
C#
Can't say I enjoyed that one. Problem explanation was poor.
public static List<int> dynamicArray(int n, List<List<int>> queries) { int lastAnswer = 0; List<List<int>> list = []; List<int> answers = []; for(int i = 0; i < n; i++) { list.Add(new List<int>()); } for(int i = 0; i < queries.Count; i++) { int y = queries[i][2]; int x = queries[i][1]; int q = queries[i][0]; int idx = (x ^ lastAnswer)%n; if (q == 1) { list[idx].Add(y); } else if (q == 2) { lastAnswer = list[idx][y % list[idx].Count]; answers.Add(lastAnswer); } } return answers; }
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 →
C#
Can't say I enjoyed that one. Problem explanation was poor.