# LeetCode 1064. Fixed Point

## Description

https://leetcode.com/problems/fixed-point/

Given an array of distinct integers `arr`, where `arr` is sorted in ascending order, return the smallest index `i` that satisfies `arr[i] == i`. If there is no such index, return `-1`.

Example 1:

```Input: arr = [-10,-5,0,3,7]
Output: 3
Explanation: For the given array, `arr = -10, arr = -5, arr = 0, arr = 3`, thus the output is 3.```

Example 2:

```Input: arr = [0,2,5,8,17]
Output: 0
Explanation: `arr = 0`, thus the output is 0.```

Example 3:

```Input: arr = [-10,-5,3,4,7,9]
Output: -1
Explanation: There is no such `i` that `arr[i] == i`, thus the output is -1.```

Constraints:

• `1 <= arr.length < 104`
• `-109 <= arr[i] <= 109`

Follow up: The `O(n)` solution is very straightforward. Can we do better?

## Explanation

Just check if the element’s value equals to its index.

## Python Solution

``````class Solution:
def fixedPoint(self, arr: List[int]) -> int:

for i, num in enumerate(arr):
if num == i:
return i

return -1``````
• Time Complexity: O(N).
• Space Complexity: O(1).
{"ft_lang_label":"__label__en","ft_lang_prob":0.62187475,"math_prob":0.9937185,"size":994,"snap":"2021-43-2021-49","text_gpt3_token_len":322,"char_repetition_ratio":0.10909091,"word_repetition_ratio":0.01775148,"special_character_ratio":0.36217305,"punctuation_ratio":0.24380165,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9991155,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-10-27T18:58:39Z\",\"WARC-Record-ID\":\"<urn:uuid:dafa3a86-8f05-4700-b5a8-6125983e9b6b>\",\"Content-Length\":\"35418\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:84a77bad-1a5a-41ab-8785-3de848c1767c>\",\"WARC-Concurrent-To\":\"<urn:uuid:031e4514-dcbd-444b-9b6b-8cbd57c2496f>\",\"WARC-IP-Address\":\"72.44.43.28\",\"WARC-Target-URI\":\"https://goodtecher.com/leetcode-1064-fixed-point/\",\"WARC-Payload-Digest\":\"sha1:ZHQ53N577HQSC4KFGWKSH62Q4NKJGWXR\",\"WARC-Block-Digest\":\"sha1:2UOWM5WO3H2FV2EBHZ35RN4QLJ3ZFQX6\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-43/CC-MAIN-2021-43_segments_1634323588242.22_warc_CC-MAIN-20211027181907-20211027211907-00140.warc.gz\"}"}