Ad
  • Custom User Avatar

    That makes sense, thanks !

  • Custom User Avatar

    Well, you'll find that the answers can be calculated by dividing n by 2 until it's <= 2. Dividing by 2 constantly is the opposite of multiplying by 2 constantly which is just n^2. Opposite of exponential is logarithm, so log 2.

    The rule is called base change rule(since you can change the base, look it up if you're confused about that part). I didn't know I could use log2() instead so I went with this.

  • Custom User Avatar

    Would you mind explaining the logic behind the logarithmic formula ?

  • Custom User Avatar

    @Radu22 ... Yeah .. Nice Code Bro .. you know that's was my intial Solution to the Kata :blush: :blush: .. Also You can enhance it by simple devise ...

    • You can Save the First two Lines of code By Simple devise , Set :wink: :wink: , Which stores only Unique Values in Sorted Form .
    • Memory-friendly solution , as you consumed only one variable .. Nice touch
    • Expected Time Compleity O(n) . Bravo :yum: :yum:
    • Happy to follow you Bro .. Hope you the best .. regards .. Zizou