Untitled

mail@pastecode.io avatar
unknown
java
15 days ago
586 B
5
Indexable
Never
public class Solution
{

  public boolean diffPossibleHelper(int[] arr, int l, int r, int k){

if(l>=r)
return false;
    if(arr[r]-arr[l]==2)
    return true;

    int mid=l+(r-l)/2;

    if(arr[r]-arr[mid]==2 || arr[mid]-arr[l]==2)
    return true;

    return diffPossibleHelper(arr,l,mid-1,k) || diffPossibleHelper(arr,mid+1,r,k);


  }
    public boolean diffPossible(int[] arr, int k)
    {
        //You Can Code Here

      int left=0;
      int right=arr.length-1;
      return diffPossibleHelper(arr,left, right, k);
     


      
    
    }
}
Leave a Comment