#C14526. Fixed Point Finder

    ID: 44185 Type: Default 1000ms 256MiB

Fixed Point Finder

Fixed Point Finder

You are given a sorted array of unique integers. A fixed point in the array is an index i such that \(A[i] = i\). Your task is to find any fixed point in the array using an efficient algorithm (binary search) and output its index. If no fixed point exists, output \(-1\).

Note: The array is sorted in increasing order and all integers are unique, which guarantees that a binary search approach can be applied.

Examples:

  • For the array [-10, -5, 0, 3, 7], the fixed point is at index 3 because \(A[3] = 3\).
  • For the array [0, 2, 5, 8, 17], the fixed point is at index 0 because \(A[0] = 0\).
  • For the array [-10, -5, 3, 4, 7, 9], there is no fixed point, so the output is \(-1\).

inputFormat

The first line contains an integer n, the number of elements in the array.

The second line contains n space-separated integers representing the sorted array.

outputFormat

Output a single integer representing the index of the fixed point if it exists; otherwise, output \(-1\).

## sample
5
-10 -5 0 3 7
3