Skip to content
We areTOP 1%

Count of Smaller Numbers After Self

HardLeetCodeSegment Tree & Fenwick Tree
Solve on LeetCode(opens in a new tab)
Track your progress
First attempt
Re-solve after a few days
Final pass before interviews
Approach hintTry it first, then reveal

Compress values to ranks and scan from the right. Before inserting the current rank into a Fenwick tree, query how many strictly smaller ranks are already present. O(n log n).

More in Segment Tree & Fenwick Tree

Segment Tree & Fenwick Tree questions
#ProblemPlatformDifficultyOpen1st1st Visit2nd2nd VisitRevRevise
1Range Sum Query - MutableLeetCodeMedium Solve Range Sum Query - Mutable on LeetCode (opens in a new tab)
2Xenia and Bit OperationsCodeforcesMedium 1700Solve Xenia and Bit Operations on Codeforces (opens in a new tab)
3Count of Smaller Numbers After SelfLeetCodeHard Solve Count of Smaller Numbers After Self on LeetCode (opens in a new tab)
4Pashmak and Parmida's problemCodeforcesHard 1800Solve Pashmak and Parmida's problem on Codeforces (opens in a new tab)
5Count of Range SumLeetCodeHard Solve Count of Range Sum on LeetCode (opens in a new tab)
6Enemy is weakCodeforcesHard 1900Solve Enemy is weak on Codeforces (opens in a new tab)
7MultisetCodeforcesHard 1900Solve Multiset on Codeforces (opens in a new tab)
8Longest Increasing Subsequence IILeetCodeHard Solve Longest Increasing Subsequence II on LeetCode (opens in a new tab)
9Sereja and BracketsCodeforcesHard 2000Solve Sereja and Brackets on Codeforces (opens in a new tab)
10XOR on SegmentCodeforcesHard 2000Solve XOR on Segment on Codeforces (opens in a new tab)
11SUM and REPLACECodeforcesHard 2000Solve SUM and REPLACE on Codeforces (opens in a new tab)
12Ant colonyCodeforcesHard 2100Solve Ant colony on Codeforces (opens in a new tab)
13A Simple TaskCodeforcesHard 2300Solve A Simple Task on Codeforces (opens in a new tab)

Sign in to track your progress

Your checkboxes, streak and activity heatmap are saved to your account and sync across devices. It is free.
Sign in with email

New here? Create an account