- You Are Given A String Representing A Sequence Of N Arrows Each Pointing In One Of The Four Cardinal Directions Up 1 (145.7 KiB) Viewed 37 times
You are given a string representing a sequence of N arrows, each pointing in one of the four cardinal directions: up ('^
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
You are given a string representing a sequence of N arrows, each pointing in one of the four cardinal directions: up ('^
You are given a string representing a sequence of N 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. Examples: 1. Given S = "^vv<v", the function should return 2. After rotating both the first ('^') and fourth ('<') arrows downwards ('v'), all of the arrows would point down. 2. Given S = "v>>>vv", the function should return 3. After rotating the first, fifth and sixth arrow rightwards, all of the arrows would point right. 3. Given S = "<<<" the function should return 0. All of the arrows already point left. Assume that: N is an integer within the range [1..100]; string S consists only of the following characters: || A|| ' and/or ">". In your solution, focus on correctness. The performance of your solution will not be the focus of the assessment.