Sorted Elements
Give a list of numbers nums, return the number of elements that are in the correct indices, if the list were to be sorted.
Constraints
n ≤ 100,000wherenis the length ofnums
https://binarysearch.com/problems/Sorted-Elements
Examples
Example 1
Input
- nums =
[1, 7, 3, 4, 10]
Output
- answer =
2
Explanation
Comparing nums and its sorted version we find that elements 1 and 10 are in their correct positions.
[1, 7, 3, 4, 10]
[1, 3, 4, 7, 10]
Leave a comment