title: Cracking the coding interview #9.3: magic index algorithm
body: <p>I am currently doing this problem from the book cracking the coding interview: </p>
  
  <p>9.3. A magic index in an array A[0...n-1] is defined to be an index such that
  A[i] = i. Given a sorted array of distinct integers, write a method to find a
  magic index, if one exists, in array A.</p>
  
  <p>And here is my code: </p>
  
  <pre><code>def magic_index(seq, start = None, end = None):
      if start is None:
          start = 0
  
      if end is None:
          end = len(seq) - 1
  
      if start &gt; end:
          return -1
  
      index = (start + end) // 2
      if index == seq(index):
          print("Equal to index. Value of index = " + index)
          return index
  
      if index &gt; seq[index]:
          print("Greater than loop. Value of Index =" + index)
          return magic_index(seq, start=index + 1, end=end)
      else:
          print("Else part of Greater. Value of index = " + index)
          return magic_index(seq, start=start, end=index - 1)
  
  
  def main():
      magic_index(seq=[1, 2, 3, 4, 6], start=None, end=None). 
  </code></pre>
  
  <p>However, when i run my code. I am not getting the proper output. Is there any help or advice I could get? Thanks in advance</p>