Maximize Fixed Points After Deletions

You are given an integer array nums.

A position i is called a fixed point if nums[i] == i.

You are allowed to delete any number of elements, including zero, from the array. After each deletion, the remaining elements shift left, and indices are reassigned starting from 0.

Return an integer denoting the maximum number of fixed points that can be achieved after performing any number of deletions.

Example 1
Inputnums = [0,2,1]
Output2
Delete nums[1] = 2 so the array becomes [0, 1], where both indices are fixed points.
Example 2
Inputnums = [3,1,2]
Output2
Do not delete any elements; nums[1] = 1 and nums[2] = 2 are fixed points.

Constraints

  • 1 <= nums.length <= 10^5
  • 0 <= nums[i] <= 10^5

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate