I'm new to Python, and I'm trying to solve the following problem:
Given a string representing a sequence of N
arrows, each pointing in one of the four cardinal directions: up (^
), down(v
), left (<
), right(>
), write a function that, given a string S
denoting the direction of the arrows, returns the minimum number of arrows that must be rotated to make them all point in the same direction.
CodePudding user response:
Find the most common direction among the original orientations of the arrows. Then, the minimum number of arrows that need to be rotated is the number of arrows that aren't in the most common orientation.
This answer is deliberately incomplete, per the suggestions in this MSE post. If, after several days, you are still stuck, post a comment, and I would be happy to advise further.
CodePudding user response:
One way is to find the direction that has the most arrows pointing that direction. Once you find the direction with most occurances , you subtract that from the total number of arrows (N) Below is something similar to what you might need. Find the most common element in a list