Count Strictly Smaller Array Occurrences for Each Value
Company: Amazon
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: easy
Interview Round: Other
### Problem
For each original position i, return how many array entries are strictly less than nums[i]. Count duplicate smaller entries separately, but do not count equal values.
```cpp
class Solution {
public:
vector<int> smallerNumbersThanCurrent(vector<int>& nums);
};
```
### Examples
**Example 1:**
```text
Input: nums = [4,1,4,2]
Output: [2,0,2,1]
Explanation: Each4 has the two smaller entries1 and2;2 has only1 below it.
```
**Example 2:**
```text
Input: nums = [0,0]
Output: [0,0]
Explanation: Equal values are not smaller than each other.
```
### Constraints
- The array contains 2 to 500 integers.
- Every value lies in `[0,100]`.
### Contract considerations
Output positions correspond to the original array order.
```hint Read the boundary condition
Count smaller occurrences separately, preserve original output positions, and exclude equal-valued entries.
```
### Boundary reminders
Output positions correspond to the original array order.
Overview: Count Strictly Smaller Array Occurrences for Each Value. For each original position i, return how many array entries are strictly less than nums[i].
Count Strictly Smaller Array Occurrences for Each Value
Amazon
Aug 21, 2026
easySoftware EngineerOtherCoding & Algorithms
0
0
Problem
For each original position i, return how many array entries are strictly less than nums[i]. Count duplicate smaller entries separately, but do not count equal values.
class Solution {
public:
vector<int> smallerNumbersThanCurrent(vector<int>& nums);
};
Examples
Example 1:
Input: nums = [4,1,4,2]
Output: [2,0,2,1]
Explanation: Each4 has the two smaller entries1 and2;2 has only1 below it.
Example 2:
Input: nums = [0,0]
Output: [0,0]
Explanation: Equal values are not smaller than each other.
Constraints
The array contains 2 to 500 integers.
Every value lies in
[0,100]
.
Contract considerations
Output positions correspond to the original array order.
Boundary reminders
Output positions correspond to the original array order.