Loading...
You are given an integer array nums.
nums
Let sorted be nums arranged in non-decreasing order. Return the number of indices i where nums[i] != sorted[i].
sorted
i
nums[i] != sorted[i]
Input: nums = [1, 1, 4, 2, 1, 3] Output: 3 Explanation: sorted = [1, 1, 1, 2, 3, 4]. Indices 2, 4, and 5 differ.
Input: nums = [5, 1, 2, 3, 4] Output: 5 Explanation: sorted = [1, 2, 3, 4, 5]. Every index differs.
Input: nums = [1, 2, 3, 4, 5] Output: 0
nums.length
nums[i]
Click "Run" to test with sample cases or "Submit" to run all tests.