Ad
  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    This solution has a time complexity of O(n^2) in the worst case scenario, where n is the length of the input string.

    This is due to the use of the contains() method, which loops through the remaining substring to check if a character appears more than once.

    In the worst case scenario, this will cause the loop to be repeated n times, resulting in O(n^2) time complexity.

  • Custom User Avatar

    Brilliant solution. It uses a arithmetic series formula to directly compute the sum of all multiples of 3 or 5 below a given number.

    Moral of the Story: Regardless how much we practiced in DSA, if we neglect the training on our math intuition, we will totally misses the chance to convert our code into O(1)!

  • Custom User Avatar

    When you spent 40 minutes creating a recursive method because you saw the word "Recursive sum"...
    .
    .
    .
    .

    And you saw others solved it with the math approach using 1 liner..

    dude (;-;)/