DEV Community

Cover image for 6-10PM challenge problem #006 solution
akbhairwal
akbhairwal

Posted on

1

6-10PM challenge problem #006 solution

Shifted Array Search

Solution for the Problem#006 is provided in Java language.

Test cases :

Test case #1
input: [2], 2

Test case #2
input:[1,2], 2

Test case #3
input: [0,1,2,3,4,5], 1

Test case #4
input : [1,2,3,4,5,0], 0

Test case #5
input : [9,12,17,2,4,5], 17

Test case #6
input : [9,12,17,2,4,5,6], 4

Solution



static int shiftedArrSearch(int[] shiftArr, int num) {  
     if(shiftArr.length>0){
      return find(shiftArr,0,shiftArr.length-1,num);
    }else return -1;
  }
  
  
 static int find(int[] arr, int l, int h, int num){
    
   
    int median = (l+h)/2;
    if(arr[median]==num) return median;
     if(l==h) return -1;
      return Integer.max(find(arr,l,median,num), find(arr,median+1,h,num));
  }

AWS GenAI LIVE image

Real challenges. Real solutions. Real talk.

From technical discussions to philosophical debates, AWS and AWS Partners examine the impact and evolution of gen AI.

Learn more

Top comments (0)

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay