Skip to content

Commit 686233b

Browse files
committed
java_program
1 parent b190cb7 commit 686233b

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
2+
// Given an array arr integers. Assume sz to be the initial size of the array. Do the following operations exactly sz/2 times. In every kth (1<= k <= sz/2) operation:
3+
4+
// Right-rotate the array clockwise by 1.
5+
// Delete the (n– k + 1)th element from begin.
6+
// Now, Return the first element of the array.
7+
8+
9+
import java.io.*;
10+
import java.lang.*;
11+
import java.util.*;
12+
13+
14+
class Abhishek {
15+
public static void main(String[] args) throws IOException {
16+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
17+
int t = Integer.parseInt(br.readLine());
18+
while (t-- > 0) {
19+
String line = br.readLine();
20+
String[] tokens = line.split(" ");
21+
22+
// Create an ArrayList to store the integers
23+
ArrayList<Integer> arr = new ArrayList<>();
24+
25+
// Parse the tokens into integers and add to the array
26+
for (String token : tokens) {
27+
arr.add(Integer.parseInt(token));
28+
}
29+
30+
Solution obj = new Solution();
31+
int res = obj.rotateDelete(arr);
32+
33+
System.out.println(res);
34+
}
35+
}
36+
}
37+
38+
39+
class Solution {
40+
public static int rotateDelete(ArrayList<Integer> arr) {
41+
// code here
42+
int n = arr.size();
43+
if(n == 1 || n == 2)return arr.get(n-1);
44+
45+
int[] b = {3, 2, 3, 3};
46+
int a = 3, j = 0;
47+
while(a + 4 <= n){
48+
a += 4;
49+
j++;
50+
}
51+
52+
for(int i = 0; i < 4; i++){
53+
if(a+i == n)return arr.get(b[i]+j-1);
54+
}
55+
return 0;
56+
}
57+
}

0 commit comments

Comments
 (0)