Ad
  • Custom User Avatar

    I initially agreed until I started considering runtime complexity. The runtime complexity of this solution is O(n) while a non-bitwise solution will typically be O(nlogn) at best (sort and then count is the best I can think of).

  • Custom User Avatar

    For this one, I was able to make a one liner, but I detest RegEx, so I did it the long way and made it a one line that goes off the right side of the screen lol

  • Custom User Avatar

    This actually doesn't work... I put a "/ 3" in at the end of the divisible by 15 if variation. Because of this, every number x divisible by 15 that is input will be off by x in the negative direction. To correct this, the first three if loops could be collapsed into one that says (value % 3 == 0 || value % 5 == 0).

    Also, after some testing, it turns out the mathematical solution above is more efficient with larger numbers whereas the solution involving iterating through all of the numbers is faster on smaller numbers.