Ad
  • Custom User Avatar

    Fair enough; "inefficient" was a poor choice of word. I was referring more to DRY, and should've said "redundancy".

  • Custom User Avatar

    the substring ... twice

    The second slice is taken only once during the whole execution process, and having an additional O(n) operation in an O(n^2) algorithm doesn't really change anything.

  • Custom User Avatar
  • Custom User Avatar

    In three lines of code you manage to calculate the length of s three times, the substring s[:i] twice, and the pattern length len(s) // i twice. So much inefficiency packed into such a tiny space, it's actually impressive.

  • Custom User Avatar

    I have haters? thats cool.

    thx for the snippet

  • Custom User Avatar

    Clever Kata. Don't listen to the haters, this is a great exercise. However,

    Input - N - integer greater than 2 - number of chairs. Output should positive integer too - last patient's chair's number

    The formatting of this passage is pretty gnarly. Since this passage isn't part of the key to the puzzle, I'd recommend rewriting:

    Input: number of chairs N, an integer greater than 2.
    Output: a positive integer, the last patient's chair number.
    
  • Custom User Avatar

    There is an upper limit of occurrence for the highest possible value. So we are taking the first n of the sorted elements. The highest possible value can be in the original array more times before other smaller numbers which should be accepted instead.

  • Custom User Avatar

    Obviously this can be done with a simple dictionary, but I rarely ever use Enum so I figured I'd practice. Genuinely curious if using Enum here is best practices...?

  • Custom User Avatar

    Oooof, I'm embarassed by my pattern now. TIL about \2.

  • Custom User Avatar

    Super confused by the tests and the description. Are we taking the first n unique minimum elements? Or just the first n of the sorted elements? Or something else entirely? My current solution only deviates in the last few elements of these long lists, which seems like super strange behavior to me. An example:

    [6, 1, 2, 6, 4, 7, 4, 6, 5, 7, 6, 3, 6, 7, 3, 8, 1, 8, 4, 8, 7, 8, 4, 8, 6, 7, 4, 8, 8, 1, 4, 2, 1, 8, 4, 6, 6] # mine
    [6, 1, 2, 6, 4, 7, 4, 6, 5, 7, 6, 3, 6, 7, 3, 8, 1, 8, 4, 8, 7, 8, 4, 8, 6, 7, 4, 8, 8, 1, 4, 2, 1, 4, 6, 6, 1] # correct
                                                                                                        ^ first deviation, what would cause this?!
    

    In the "correct" solution you can clearly see that an 8 is left out. In mine, the last four elements are [8, 4, 6, 6] and in the "correct" solution the last four are [4, 6, 6, 1] so clearly the two are just offset by this one extra element in mine, BUT the "correct" solution includes other 8s, so clearly the "correct" solution considers 8 to be one of the n minimum elements... I don't understand why the "correct" solution throws this particular 8 out when others are let in...

  • Custom User Avatar
  • Custom User Avatar
  • Custom User Avatar

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

  • Custom User Avatar

    Two list comps is bad. Rebinding a keyword is even worse. Unreal that this is the top solution.

  • Custom User Avatar

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

  • Loading more items...