Ad
  • Custom User Avatar

    Not a kata suggestion.

  • Custom User Avatar

    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'?

  • Custom User Avatar

    Let's say that you have following inputs:

    s1 = "a" * 100_000
    s2 = "a" * 100_000
    

    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?

  • Custom User Avatar

    i used js :(

  • Custom User Avatar

    hey man, can you help me out with my attempt
    i have a question below you
    thanks

  • Custom User Avatar

    Nice Kata

  • Custom User Avatar

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

  • Custom User Avatar

    Fixed Java, should no longer accept O(n^2) solutions.

  • Default User Avatar

    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 and s2).

    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.

  • Custom User Avatar

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

  • Custom User Avatar

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

  • Custom User Avatar

    std::string::npos is a size_t (kind of). It's just a number. How is a number too slow?

  • Custom User Avatar

    Here is a tip for C++:

    This is slow:

    std::string::npos

  • Default User Avatar

    Why do you want to put a colon there? We need to separate two arguments (r and s) that are passed to the function.

  • Custom User Avatar

    Can somebody explain to me why the colon is not take into consideration when using "auto r" and "auto s"?