Ad
  • Custom User Avatar
  • Custom User Avatar

    yes, this is how it's supposed to work :)

  • Custom User Avatar

    Well, cheesing the kata in unexpected ways is also fun! So there are no problems with that.

    The only problen I can think of is that it might be too obvious.

  • Custom User Avatar

    Well, it shows why one shouldn't do too much performance tuning in JS, it's somewhat magical! :P

    But yeah, if a correct approach is used the total runtime (including the 6 seconds spent by the test code itself) should be less than 10-11 seconds.

  • Custom User Avatar

    If you're trying to get the keys of an object and looping through them for every array element that's going to be slow, because getting the keys of an object is slow. If you change the above to

    for (let k=1; k<=3; i++)
    

    It finishes in 8.5 seconds. This is a language feature, not a kata feature or algorithmic feature.

    Also, in the end, this approach is still O(n^2), so I think you might as well drop this approach at once and think of a better algorithm :)

  • Custom User Avatar

    It's not.

    You're looping through your histogram every loop, which, in general, will have O(n) entries (since duplicates are rare), so your algorithm is not O(n), but O(n^2).

  • Custom User Avatar

    That's the point, O(n^2) is not a fast enough algorithm for this kata.

    Otherwise why'd you think this is 3kyu? :P

  • Custom User Avatar

    this is not an issue with the kata.