bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 1064. Fixed Point

1064. Fixed Point

Leetcode Solutions

Binary Search Approach

Algorithm

  1. Initialize left to 0 and right to arr.length - 1.
  2. Initialize answer to -1 to indicate that no fixed point has been found yet.
  3. While left <= right, do the following: a. Calculate mid as (left + right) / 2. b. If arr[mid] == mid, update answer to mid and set right to mid - 1 to search for a smaller index. c. If arr[mid] < mid, set left to mid + 1. d. If arr[mid] > mid, set right to mid - 1.
  4. Return answer.
UML Thumbnail

Linear Search Approach

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...