/* Order Agnostic Binary Search is a method of finding the sorted array in either ascending or descending order. */ public class OrderAgnosticBS { public static void main(String[] args) { int[] arr={1,2,3,4,5,6,7,8,9}; int target=7; int ans=orderAgnosticBS(arr,target); System.out.println(ans); } static int orderAgnosticBS(int[] arr,int target){ int start=0; int end=arr.length-1; //find array is sorted in ascending or descending order boolean isAsc;// boolean isAsc = arr[start]target) { end=mid-1; } else if(arr[mid]target){ start=mid+1; } } } return -1; } }