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.
Print the input yourself: https://docs.codewars.com/training/troubleshooting/#print-input
I would love to see random tests so I can figure out what's wrong with my code...
This comment is hidden because it contains spoiler information about the solution
This would be the best, yes, but there's one more, easier possibility. You can change the outer loop in a way that even if you keep both the loop and
count
, your solution would be reduced to O(n).Getting back to my example: how many times do you need to count occurrences of
'a'
in both strings to know the answer? How many times does your solution count occurrences of'a'
?This comment is hidden because it contains spoiler information about the solution
Let's say that you have following inputs:
What would be an expected answer? Would you have an idea why your solution is slow for this input, and how to make it faster?
i used js :(
hey man, can you help me out with my attempt
i have a question below you
thanks
Nice Kata
This comment is hidden because it contains spoiler information about the solution
Fixed Java, should no longer accept O(n^2) solutions.
Hi;
In the Python version of this kata there are several random tests at the end of the test suite with over
100,000+
elements in each string (s1
ands2
).Your current approach is "correct" - the logic is correct - and will work OK for small input string lengths, but it will fail for such large tests.
The reason why is that you are iterating over every element of s1 for every element of s2 - in other words you are performing up to
100,000 * 100,000
operations which is a huge number.Basically, you need to find a more efficient approach that does not require so many calculations.
This comment is hidden because it contains spoiler information about the solution