Count Later Smaller Ranks Problem
Count Later Smaller Ranks Problem — ExecCode Hard DSA Practice
Solve the Count Later Smaller Ranks problem on ExecCode. Free online hard DSA practice in Two Pointers. Write and run code in Java, C++, Python — no signup required to run.
Problem description
For every index i you must count how many later indices hold a strictly smaller value. This is inversion counting per starting index and is a common OA upgrade of 'count inversions'. Nested loops fail. Return an array ans where ans[i] is the number of indices j > i with nums[j] < nums[i]. You are given: nums — integer array Return integer array of the same length. The last index always contributes 0.
Examples
Input {'nums': [5, 2, 6, 1]}; Output [2, 1, 1, 0]. Input {'nums': [1, 2, 3]}; Output [0, 0, 0]. Input {'nums': [3, 3, 3]}; Output [0, 0, 0]
Constraints
Equal values are not counted
Practice Count Later Smaller Ranks free on ExecCode. Browse DSA problems, topic map, and placement guides.