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.
Exactly the solution I came up with :)
This is not efficient
Using .count() inside a loop is quite costly. An alternative is to use 'Counter' from the 'collections' library:
from collections import Counter
yeah, but with the spoiler flag, thx (comments are visible from the dashboard)
This comment is hidden because it contains spoiler information about the solution
@rowcased i can only say thanks..... I was searching for an explanation to the kata and the example is.... an explanation by self
True, the fact that the alphabet is limited makes my analysis too pessimistic.
A standard implementation of str.count(char) entails an iteration through the elements of str. Without knowing the details of the Python implementation, it is most likely still an expensive operation. The solution is far from optimal and shouldn't be considered best practice. "Too slow" still holds.
You can solve the problem and only loop through s1 and s2 once respectively.
The timeouts are because the iterations are on s2 can be over 600,000. Using set(s2) limits the iteration to 26 because there are only 26 unique aphabets, so the iterations are 26 or less.
Great example @rowcased hahaha
Because in string there are lot of repeated letters while
set(s2)
keep only one of them. So only iterating once per letter.Please use spoiler flag next time.
This comment is hidden because it contains spoiler information about the solution
I had the same solution but met Time Limit Exceed. I used Counter instead
Now this won't pass all test, cause it's slow.
looks like it's not:
https://stackoverflow.com/a/19974533/3002731
Loading more items...