We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
int row = queries.size();
int lastanswer = 0;
for(int i = 0 ; i < row; i++)
{
int q = queries[i][0];
int x = queries[i][1];
int y = queries[i][2];
int idx =( x ^ lastanswer)% n;
//Query type 1
if(q == 1)
{
// cout<<idx <<endl;
arr[idx].push_back(y);
// cout<<arr[idx] [0] << endl;
}else if(q == 2) //Query type 2
{
int id = y % arr[idx].size();
lastanswer = arr[idx][id];
ans.push_back(lastanswer);
}
}
return ans;
}
Cookie support is required to access HackerRank
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 →
vector dynamicArray(int n, vector> queries) {
vector> arr(n,vector()); vector ans;
}