public static int pos=-1;
public static int find(int arr[],int n,int si){
if(si==arr.length-1){
return pos;
}
if(arr[si]==n){
pos=si;
}
return find(arr,n,si+1);
}
public static int pos=-1;
public static int find(int arr[],int n,int si){
if(si==arr.length-1){
return pos;
}
if(arr[si]==n){
pos=si;
}
return find(arr,n,si+1);
}
Hi @Kunal.Verma,
It would work but it is suggested to use the other way where you do not take a static variable as these questions are for learning and the original method is quite important and basic step for learning complex problems.However this is a innovative solution and is correct.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.