Smaller Elements Count Problem Statement

Given an array of size N, return a count array such that COUNT[i] equals the number of elements which are smaller than ARR[i] on its right side.

Input:

Input Format:
The first line of input contains an integer 'T' denoting the number of test cases.
The first line of each test case contains 'N' denoting the number of elements in the array.
The next line contains 'N' space-separated integers denoting the elements of the array.

Output:

Output Format:
For each test case, return the array where the i-th element stores the count for the i-th 
element in the array.

Example:

Input:
ARR = [4,2,1,5]
Output:
[2,1,0,0]
Explanation:
The number of elements smaller than 4 on its right side is 2.
The number of elements smaller than 2 on its right side is 1.
The number of elements smaller than 1 on its right side is 0.
The number of elements smaller than 5 on its right side is 0.
Hence, the count array is [2,1,0,0].

Constraints:

  • 1 <= T <= 10
  • 1 <= N <= 3000
  • -10^3 <= arr[i] <= 10^3
  • Where ‘i’ varies from 1 to ‘N’ where 'N' is the length of the array.
  • Time Limit: 1 sec
AnswerBot
4mo

Return an array where each element represents the count of smaller elements on its right side in the given array.

  • Iterate through the array from right to left and maintain a sorted list of elements enc...read more

Help your peers!
Select
Add answer anonymously...

SPRINKLR Full Stack Engineer interview questions & answers

A Full Stack Engineer was asked Q. Rank from Stream Problem Statement Given an array of integers ARR and an integer...read more
A Full Stack Engineer was asked Q. Smaller Elements Count Problem Statement Given an array of size N, return a coun...read more
A Full Stack Engineer was asked Q. Minimum Operations to Equalize Array Given an integer array ARR of length N wher...read more

Popular interview questions of Full Stack Engineer

A Full Stack Engineer was asked Q1. Rank from Stream Problem Statement Given an array of integers ARR and an integer...read more
A Full Stack Engineer was asked Q2. Smaller Elements Count Problem Statement Given an array of size N, return a coun...read more
A Full Stack Engineer was asked Q3. Minimum Operations to Equalize Array Given an integer array ARR of length N wher...read more
SPRINKLR Full Stack Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits