Not able to get the question

import java.util.*;
public class Main {
public static void main(String args[]) {
// Your Code Here
Scanner scn=new Scanner(System.in);
int n=scn.nextInt();
int arr[]=new int[n];
for(int i=0;i<n;i++){
arr[i]=i+1;
}
System.out.println(sum(arr,arr.length-1));
}
public static int sum(int arr[],int idx){

   if(idx<0){
	   return 0;
   }
   int sum=arr[idx]+sum(arr,idx-2);
   return sum;
}

}

it is given in the input that the ith index will be the value of ith coin so according to this our array will be sorted from 1 to n like we have the example of n=4 so the respective array will be 1,2,3,4 and according if Piyush wants to win he should always pick the coin or element from array last index and the index must always decrease by 2 because another guy also want to win .

hi @guptadev354
you have misunderstood the question the values are not giving in sorted order.
"the input that the ith index will be the value of ith coin " this line simply means that the at the ith index of the array you will get the value of ith coin and the value can be arbitrary.

okay got it now thanks !

@guptadev354
please mark your doubt as resolved in my doubt section and rate me as well :blush::blush: