Skip to content
Onsite

Count Elements With Smaller Element on Left

EasyP3Coding

For each element of nums, look at the elements to its left. Return how many elements have at least one strictly smaller element somewhere to their left.

The first element never counts, because nothing is to its left.

Example 1

Input
nums = [3,1,4,1,5]
Output
2
Why
Only 4 and 5 have a smaller element to the left; the second 1 has no strictly smaller one.

Example 2

Input
nums = [5,4,3]
Output
0

Example 3

Input
nums = [1,2,3]
Output
2

Constraints

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

Hints

Run checks the 3 visible tests, Submit all 10.