Ad
  • Custom User Avatar

    complexity of this solution seems very high :(

  • Custom User Avatar
    smaller([5, 4, 1, 2, 1]) === [4, 3, 0, 1, 0]
    

    For every item in the left, you should return how many numbers on the right are smaller
    So:

    5 ==> 4, 3, 2, 1 ==> 4
    4 ==> 3, 2, 1 ==> 3
    1 ==> ~~2~~, ~~1~~ ==> 0
    2 ==> 1 ==> 0
    1 ==> ==> 0
    

    There's an easy greedy solution that involves complexity similar to O(n * n), so the proposed tests would pass, but final tests will not due to timeout.
    I'm trying to figure out how to make this O(n) :D

    Good luck!