Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
I get that the description says 'right away', so you're only supposed to cancel out immediately adjecent opposites. However that makes no sense as the description also says
which clearly sounds like an optimization. Especially the last example in the description
["NORTH", "WEST", "SOUTH", "EAST"]
makes no sense why it shouldn't be reduced to[]
. If you simply follow these instructions as the early settler you would literally end where you started and I'd be pretty upset about the worthless effort 😂Much appreciated ^^
To be fair, almost no tutorials teach you Big-O properly. I consistently hear of people that first learned about time and space complexity like 2-5 years after they already begun working as a developer.
For some reason this isn't taught and unless you prepare for interviews at companies like google, you likely won't hear of this early on.
I think it should be taught though, it really helps writing better code.
This is O(n^2), not great.
"Not all paths can be made simpler. The path
["NORTH", "WEST", "SOUTH", "EAST"]
is not reducible."NORTH"
and"WEST"
,"WEST"
and"SOUTH"
,"SOUTH"
and"EAST"
are not directly opposite of each other and can't become such. Hence the result path is itself :["NORTH", "WEST", "SOUTH", "EAST"]
."This is false because you'd end up back where you started.
The kata doesn't say that the requirement is to create the most optimal route. It asks you to create the simplified version of the route:
This kata is weird.
I used x and y coordinates to determine the destination and then used those to simply return the most optimal route.
Example:
x: -1 y: 1
would be once WEST and once NORTH.The input array was:
['EAST', 'NORTH', 'SOUTH', 'NORTH', 'WEST', 'NORTH', 'SOUTH', 'NORTH', 'SOUTH', 'WEST']
The expected answer is:
['EAST', 'NORTH', 'WEST', 'WEST']
when in reality
['NORTH', 'WEST']
would be the most optimal and time saving route.
So now I have to wonder how to get a less optimal solution to fit the weird dependencies of this kata...
Holy moly
This comment is hidden because it contains spoiler information about the solution