title: Python: Find the minimum element in a sorted and rotated array
body: <p>Trying to solve <a href="https://www.geeksforgeeks.org/find-minimum-element-in-a-sorted-and-rotated-array/" rel="nofollow noreferrer">this question</a>.</p>
  <h3 id="find-the-minimum-element-in-a-sorted-and-rotated-array-szdb">Find the minimum element in a sorted and rotated array</h3>
  <p>I do not get the min value always. Can someone help? where the issue is. I started coding after many years of gap.   I want to use recursive logic only.</p>
  <pre><code>def getMin(data,mid, start,end):
      
      if len(data[start:end]) == 1 :
          return data[start]
        
      if len(data[start:end]) == 2:
          if data[start] &lt; data[end]:
              return data[start]
          else:
              return data[end]
      
      if (data[mid] &gt;  data[mid-1] and data[start] &gt; data[end] ):
          #min is i  left array
          start = mid
          end = end
          mid =  int ((start+end)/2)
          #data = data[start:end]
          return getMin(data, mid, start,end)
      else:
          
          #min is in right array
          start = start
          end = mid+1
          mid = int ((start + mid)/2)
          #data = data[start:end]
          return getMin(data, mid, start,end)
  
  def FindMin(data):
      mid = int (len(data)/2)
      end = (len(data)) -1
      start = 0   
      val = getMin(data,mid,start,end)
      return val
      
  
  # Input
  import random as rd
  numOfElem = 10
  
  data =  sorted(rd.sample (range (1,40),numOfElem))
  print (&quot;ONLY Sorted Data is        == &quot;, data)
  
  # get random number to move element by that number
  movebysize= rd.randint(1,10)
  print (&quot;Move Sorted data by size   == &quot;, movebysize)
  
  # Make array rotated
  data = data[movebysize:] + data[:movebysize]
  print (&quot;Data Sorted and Rotated is == &quot;, data)
  
  # Find Min:
  #data = [[36, 39, 1, 4, 5, 8, 11, 12]]
  print (&quot; Min is ==== &quot;, FindMin(data))
  </code></pre>