You are given a string representing a sequence of N arrows, each pointing in one of the four cardinal directions: up ('^

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
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 ('^

Post by answerhappygod »

You Are Given A String Representing A Sequence Of N Arrows Each Pointing In One Of The Four Cardinal Directions Up 1
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 38 times
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.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply