Find Fixed Number

In this lesson, you will learn how to find a fixed number in a list using a binary search in Python.

We'll cover the following

In this lesson, we will be solving the following problem:

Given an array of nn distinct integers sorted in ascending order, write a function that returns a fixed point in the array. If there is not a fixed point, return None.

A fixed point in an array A is an index i such that A[i] is equal to i.

The naive approach to solving this problem is pretty simple. You iterate through the list and check if each element matches its index. If you find a match, you return that element. Otherwise, you return None if you don’t find a match by the end of the for loop. Have a look at the code below:

Get hands-on with 1400+ tech skills courses.