AlgoMaster Logo

Count of Smaller Numbers After Self

nums=[5, 2, 6, 1]
0 / 33
offset = 0result[i] = # of values after i that are smaller · BIT index = value + offsetnums5261result----0123BIT000000123456scan right → left · BIT (indexed by value) counts seen values smaller than each element
algomaster.io
Step:Initialize BIT of size 6. Offset = 0 (so min value 1 maps to index 1). Traverse nums right to left.