generate functionTue, 08 Nov 2022

You are given a string representing a sequence of arrows, each pointing in one of the four cardinal directions: up ('^), down (v'), left (*) or right (>'). Write a function solution that, given a string S denoting the directions of the arrows, returns the minimum number of arrows that must be rotated to make them all point in the same direction. Example: Given S= "Ayvev", the function should return 2. After rotating both the first (^) and fourth ('<) arrows downwards (v), all of the arrows would point down.

def solution(s): # write your code in Python 3.6 a = s.count('^') b = s.count('<') c = s.count('v') d = s.count('>') return min(a,b,c,d)

Questions about programming?Chat with your personal AI assistant