I'm working on a problem that requires me to remove "pairs" (north-south and east-west pairs) in an array of strings. I'm unsure of a way to approach this problem on Python.
Here's the problem:
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). (link to problem: https://www.codewars.com/kata/550f22f4d758534c1100025a)
Some test inputs and outputs:
Input : ["NORTH", "SOUTH", "SOUTH", "EAST", "WEST", "NORTH", "WEST"]
Output : ["WEST"]
Input : ["NORTH", "WEST", "SOUTH", "EAST"]
Output : ["NORTH", "WEST", "SOUTH", "EAST"]
The 2nd set of inputs and outputs don't make much sense in regards to the task. My initial thought was to use a stack, but now I'm unsure of how to do it.