Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
This comment is hidden because it contains spoiler information about the solution
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.
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)!
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 (;-;)/