Ad
  • Custom User Avatar

    I'd like to chime in on this one. I was mislead in my initial solution assuming that x ran horizontal and y vertical, despite the picture showing the origin in the upper left. Sure I could of easily read this as a cartesian plane rotated 90 degrees, but then the navigational directions oriented with north up further lead me to think it was not rotated. Nothing in the description said otherwise. Making matters worse, the example and the first test case only use switches on points where x == y ([1,1], [4,4], etc) so there's nothing in there to tip the reader off.

    So I solved it for all the example cases only to have it blow up on the real cases. It took awhile for me to figure out why, and then to refactor for the rotated coordinates.

    I suggest you make it abundantly clear by labeling the coords in the picture. A second option would be to use a non=symmetrical example.

    All that said, I really enjoyed working this one and the colorful description!

  • Custom User Avatar

    Those examples are much clearer, thanks! I was about to say if it's so hard to explain, then maybe lose the requirement :-) But then that would make it somewhat easier to solve.

  • Custom User Avatar

    99 is Wayne Gretzky's retired number. It's ALWAYS appropriate to include :)

    But really, I added it just to give a case where the first index isn't 0. Good feedback that it muddies more than helps though.

  • Custom User Avatar

    Thanks much for all the help. Went with most of what you changed and cleaned up more.

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

    This would be inaccurate. It's any element must be lower indexed than any element from other triplets. Or the second lowest indexed element in the case of a tie for the first. Words are hard! That's why I put these two specific examples in the text:

    • [99,11,4,7,9,1] returns [7,9,11]
      • the first valid sequence
        • member 11 at index 1 for set[7,9,11]
        • member 4 at index 2 for set[1,4,7]
    • [13,20,17,9,27] returns [13,20,27]
      • the first valid sequence
        • member 13 at index 0 for both valid sets [9,13,17] and [13,20,27]
        • second member 20 at index 1 for set [13,20,27]
        • second member 17 at index 2 for set [9,13,17]

    Are those not clarifying enough?

  • Custom User Avatar

    Well played sir!

    I didn't mean to imply that sorted couldn't work, since it takes extra effort to find all possible solutions and then reevaluate those against their original indexes.

    The question for me is if this then leads to higher performance, as gained from the ability to walk a sorted list.

  • Custom User Avatar

    Actually it's technically O((n-2)(n-1)n/6), which is slightyl less than n^3 / 6

    Still not as good as n^2 once you get above about 8 members, but I gotta defend my solution :-)

  • Custom User Avatar

    Great feedback, thanks! I got away from JS for a year or so while having fun with Go and now Python. let vs var is indeed good form!

    I'll also look into your fork and learn the superior test methods and provided features (didn't know randomize was a thing!)

  • Custom User Avatar

    I think you are correct on my wording being misleading or plain wrong. What I meant to say was that moving from left to right through the array, priorty is on elements of the solution array found first -- not specific of the order in the final array. So in the referenced case above, 825 is part of the answer and is the leftmost element of any in a valid solution.

    Would changing the wording to below help clarify?

    such that the first located member of the sequence will have the lowest indexed first member from the array

  • Custom User Avatar

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

  • Custom User Avatar

    You make a lot of good points. It would be trivial to add the loop and bang out 100 or so random.

    As for why I care, by profession I'm usually heading engineering orgs and like to think big picture. Part of that is to challenge the status quo and ask questions if an existing practice still makes sense, especially when multiplied by some large number due to scale. I get that optimizing CW is not my concern, but old habits die hard :-)

    FYI -- the above it part of why I'm here. After too many years managing I'm trying to get back some of my coding chops and also learning the languages that all the cool kids are coding in these days.

  • Custom User Avatar

    Agreed on that. I replaced the word set with either group or array depending on the context. That should be less misleading for the Python version specifically. I haven't tried porting to another language yet but assume that you only get one description to rule them all, so will need to keep it language agnostic.

    FYI - I plan to add JS and Go next. I'm pretty rusty in most of the other language options here.

  • Custom User Avatar

    From my point of view, the role of the random test is to prevent hardcoding answers to the tests that can be discovered through failures. So in theory just one should do the trick. What's the point of having 100? I'd rather preserve cycles on the servers if it's not adding real value.

    I chose the few that I added to cover a couple different sized lists with and without an expected sequence to be found. I would think that's sufficient coverage unless I'm missing something.

  • Loading more items...