Spread the post

Count smaller elements on right side

Given an array of integers values. Write an efficient program (algorithm) to print or Count smaller elements on right side.

Example

Suppose array contain following nodes. view input and accepted output.

Stack Areamainarray [0] 4 [1] 3 [2] 2 [3] 6 [4] 5 [5] 9size (int) =6

Output

 5 -> 6  2 -> 3  4 -> 6  3 -> 6  7 -> -1  6 -> -1 

Program for Count smaller elements on right side in c. Time complexity O(n).

Output

View process.

Stack Areamainarray [0] 4 [1] 3 [2] 2 [3] 6 [4] 5 [5] 9size (int) =6count_smallerarray(pointer)i (int) =0j (int) =5result (int) =2size (int) =6

View steps of execution

Submit your solution in comment section.

Spread the post

Recommended Posts: