However, going North, then West, then South, then East... doesn't it mean that you just return exactly where you started so the final result for the easiest path should actually be [] ?
Write a function dirReduc which will take an array of strings and returns an array of strings with the needless directions removed (W<->E or S<->N side by side).
In ["NORTH", "EAST", "WEST", "SOUTH", "WEST", "WEST"], "NORTH" and "SOUTH" are not directly opposite but they become directly opposite after the reduction of "EAST" and "WEST" so the whole path is reducible to ["WEST", "WEST"].
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"].
So:
The problem statement makes it seem like you want ALL superfluous directions removed
No, the instructions state clearly that's not the case.
The problem is people don't read the instructions well enough, and start to write code with what they think they should do instead of what they really should do. Also, they don't read the posts already written here, and open new issues.
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
However, going North, then West, then South, then East... doesn't it mean that you just return exactly where you started so the final result for the easiest path should actually be [] ?
From the description:
So:
No, the instructions state clearly that's not the case.
The problem is people don't read the instructions well enough, and start to write code with what they think they should do instead of what they really should do. Also, they don't read the posts already written here, and open new issues.