modify this code so that if element not found in array it should return -1 class…
- User
modify this code so that if element not found in array it should return -1 class Solution { public int binarysearch(int[] arr, int k) { // Code Here int start = 0; int end = arr.length - 1; while(start <= end){ int mid = start + (end - start)/2; if(arr[mid] >= k){ end = mid - 1; } else { start = mid + 1; } } return start; } }
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.