Ad
  • Custom User Avatar

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

  • Custom User Avatar

    I like this one:

    • covers every case where the total number of names could be different from the example (len(names) != 5)
    • once you figure out the indices it works very intuitively to the "story" without a lot of thought paid to mathematics or other tricks; with only a few comments, you could actually re-tell the story that this solves
    • it is also reasonably efficient, since a list is not utilized that may grow out of bounds
    • this scales decently well too; we split the chance of integer overflow across everyone in the queue, effectively mitigating the chance by the number of unique people in the queue

    Overall, not optimal but straightforward.

  • Custom User Avatar

    In retrospect:

    • The range function is unneeded, as we could just use a blank hash-table/object to start out with and have the code assume all values are 0 if undefined.
    • I could have collapsed variable initialization onto each other for common values.
    • I could have dropped the "this" from the variables in exchange for closured vars in order to make the internal values 'private' to the function; although the starting status of the code suggest to use the "this.var = value" format explicitly.
  • Custom User Avatar

    Jaden deleted his twitter, so the flavor link is no longer valid. :(
    https://twitter.com/officialjaden