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.
try this code it is very easy to understand and implement the code !!!!!!!!!!!
public class Solution {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int t = sc.nextInt();
for (int c=0;c<t;c++){
int n = sc.nextInt();
int k = sc.nextInt();
int arr[]=new int[n];
int len=0;
if(n%2==0) len=n/2;
else len=n/2+1;
int j=0;
for (int i = 0; i < len; i++) {
arr[j] = n - 1 - i;
if (i == len-1 && n%2!=0 ) {
break;
}
else arr[j + 1] = i;
j += 2;
}
for(int m=0;m<n;m++){
if(k==arr[m])System.out.println(m);
}
}
}
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Reverse Game
You are viewing a single comment's thread. Return to all comments →
try this code it is very easy to understand and implement the code !!!!!!!!!!! public class Solution { public static void main(String[] args) { Scanner sc=new Scanner(System.in);
} }