You are viewing a single comment's thread. Return to all comments →
the code is simple and easy but problem's description got me stuck.
public static List dynamicArray(int n, List> queries) { List> arr = new List>(); for(int i = 0; i < n; i++){ arr.Add(new List()); }
List<int> answersArray = new List<int>(); int lastAnswer = 0; for(int i = 0; i < queries.Count; i++){ int x = queries[i][1]; int y = queries[i][2]; if(queries[i][0] == 1){ int idx = (x^lastAnswer) % n; arr[idx].Add(y); }else if(queries[i][0] == 2){ int idx = (x ^ lastAnswer) % n; lastAnswer = arr[idx][y % arr[idx].Count]; answersArray.Add(lastAnswer); } } return answersArray; }
}
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 →
the code is simple and easy but problem's description got me stuck.
public static List dynamicArray(int n, List> queries) { List> arr = new List>(); for(int i = 0; i < n; i++){ arr.Add(new List()); }
}