title: Find pivot element in sorted and rotated array
body: <p>I am trying to find pivot element in sorted and rotated array, which returns It gives stackoverflow error. </p>
  
  <p>Below is the code: </p>
  
  <pre><code>int findPivot(int[] arr,int lo, int hi) {
  
      int mid = lo +(hi-lo)/2;
  
      if(arr[mid]&gt;arr[mid+1]) {
          return mid;
      }
      else if (arr[mid]&lt;arr[hi]) {
          return findPivot(arr,lo,mid-1);
      }else {
          return findPivot(arr,mid+1,hi);
      }
  
  }
  </code></pre>
  
  <p>How do I solve this problem?</p>