Problem statement

Write a function that takes in an array of integers and returns an array of the same length, where each element in the output array corresponds to the number of integers in the input array that are to the right of the relevant index and that are strictly smaller than the integer at that index.

In other words, the value at output[i] represents the number of integers that are to the right of i and that are strictly smaller than input[i]

Solution

Typescript
export function rightSmallerThan(array) {
 return array.map((elm, idx) => {
   let count = 0;
   let increment = idx + 1;
   while(increment < array.length) {
     if(array[increment] < elm) {
         count++;
     }
      increment ++;
   }
   return count;
  });
}
References: