Count Strictly Smaller Later Occurrences for Every Position

Quick Overview

Count Strictly Smaller Later Occurrences for Every Position. For each array position, count later entries whose values are strictly smaller; equal values do not count.

Count Strictly Smaller Later Occurrences for Every Position

Company: Google

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Other

### Problem Return counts where counts[i] is the number of indices j>i with nums[j]<nums[i]. Equal later values do not count. ```cpp vector<int> countSmaller(vector<int>& nums); ``` ### Examples ```text nums = [4,1,3,1] -> [3,0,1,0] nums = [2,2] -> [0,0] ``` ### Constraints - Length is 1 through 100000. - Values lie in [-10000,10000].

Overview: Count Strictly Smaller Later Occurrences for Every Position. For each array position, count later entries whose values are strictly smaller; equal values do not count.

Google logo
Google
Source window: 0–6 months · as of Oct 21, 2026
hardSoftware EngineerOtherCoding & Algorithms
0
0

Problem

Return counts where counts[i] is the number of indices j>i with nums[j]<nums[i]. Equal later values do not count.

vector<int> countSmaller(vector<int>& nums);

Examples

nums = [4,1,3,1] -> [3,0,1,0]
nums = [2,2] -> [0,0]

Constraints

  • Length is 1 through 100000.
  • Values lie in [-10000,10000].