Count Numbers Smaller Than Current

TCS NQT Coding Easy Go Ad-Free - ₹20/mo

Given an array of integers, for each element, count how many elements in the array are strictly smaller than it. Return an array of these counts.

Examples:

Input: [8,1,2,2,3]

Output: [4,0,1,1,3]

Explanation: For 8, four numbers (1,2,2,3) are smaller; for 1, no number is smaller; for each 2, one number (1) is smaller; for 3, three numbers (1,2,2) are smaller.

Input: [6,5,4,3,2,1]

Output: [5,4,3,2,1,0]

Input: [1,2,3]

Output: [0,1,2]

Constraints

  • 2 ≤ array length ≤ 100
  • 0 ≤ each element ≤ 1000