Question: How can the error be corrected? int func ( int [ ] arr, int size ) { if ( size = = 1 && arr

How can the error be corrected?
int func (int[] arr, int size){
if (size ==1 && arr[0]==1){
return 0; }
return fun(arr,0, size 1);}
public static int fun (int[] arr, int a, int b){
int m;
if (b < a){
return -1; }
mid =(a + b)/2;
if (1== arr[m] && 0== arr[m 1]){
return m; }
if (0== arr[m]){
return fun(arr, m +1, b);
} else {
return fun(arr, a, m 1); }}
a. Modify the method to return the index of the last 1.
b. No correction is needed.
c. Do not sort the array.
d. Change the condition to 1== arr[m] && (m==0||0== arr[m-1]).

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!