Write function smaller(arr)
that given an array arr
, you have to return the amount of numbers that are smaller to the right of that number in the index.
For example:
smaller([5, 4, 3, 2, 1]) === [4, 3, 2, 1, 0]
smaller([1, 2, 0]) === [1, 1, 0]
Tests:
smaller([5, 4, 3, 2, 1])
smaller([1, 2, 3])
smaller([1, 1, -1, 0, 0])
smaller([5, 4, 7, 9, 2, 4, 4, 5, 6])
Good luck!
This challenge comes from joh_pot on CodeWars. Thank you to CodeWars, who has licensed redistribution of this challenge under the 2-Clause BSD License!
Want to propose a challenge idea for a future post? Email yo+challenge@dev.to with your suggestions!
Top comments (8)
Simple JS solution.
TypeScript
Here is a python solution
Here is a C++ solution,
Test cases,
This is a trivial python solution.