2 ms·
Except that it's not about cycles detection in a linked list. It's about thing as simple as 'if I am where I have aleady been then I'm screwed'. You just need t
by scotty79 12y ago
Except that it's not about cycles detection in a linked list. It's about thing as simple as 'if I am where I have aleady been then I'm screwed'. You just need to remember stuff and recall it as quickly as possible, so hashmap. It's finite because size of the board is finite. End of story.
His solution is just worse. His solution is slower because he picked inadequate data structures and he used algorithm for finding cycles that's only interesting because it can operate in fixed space but it's use is totally stupid because he constructs the linked list himself and that takes in worst case amount of memory proportional to number of fields on the board.
It's a task you can figure out just by thinking few minutes about the problem without any prior knowledge so a good test question for checking your ability to think.
The only reason you might come up with the solution OP presented is if you were told to 'do it as if js was haskell or something'
- picks_at_nits 12y agoWhere does the solution given use On space?
- scotty79 12y agoSorry. My mistake. It doesn't. It cheats its way out of it by running game twice instead. That's why it needed to turn Game into iterable or at least generator function not just a generator intance.
- picks_at_nits 12y agoNot to worry. I have it on good authority that the author thinks all three fictional parties are at fault.
- deleted 12y ago[deleted]