Skip to content

Commit 41f0ea4

Browse files
authored
Add files via upload
1 parent ed2b1af commit 41f0ea4

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

Arrays/dynamicArray.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// https://www.hackerrank.com/challenges/dynamic-array/problem
2+
3+
import java.io.*;
4+
import java.util.*;
5+
import java.text.*;
6+
import java.math.*;
7+
import java.util.regex.*;
8+
9+
public class Solution {
10+
11+
public static void main(String[] args) {
12+
13+
Scanner scan = new Scanner(System.in);
14+
int n,q,lastAns=0,i,j,w,temp,size;
15+
16+
n = scan.nextInt();
17+
q = scan.nextInt();
18+
ArrayList<ArrayList<Integer>> al = new ArrayList<ArrayList<Integer>>();
19+
20+
for(i=0;i<n;i++)
21+
al.add(new ArrayList<Integer>());
22+
23+
for(w=0;w<q;w++)
24+
{
25+
int v,x,y;
26+
v = scan.nextInt();
27+
x = scan.nextInt();
28+
y = scan.nextInt();
29+
30+
if(v==1)
31+
{
32+
temp = (x^lastAns)%n;
33+
al.get(temp).add(y);
34+
}
35+
36+
else
37+
{
38+
temp = (x^lastAns)%n;
39+
size = al.get(temp).size();
40+
lastAns = al.get(temp).get(y%size);
41+
System.out.println(lastAns);
42+
}
43+
44+
}
45+
46+
}
47+
}

0 commit comments

Comments
 (0)