Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You are given an input string that controls the movement of a robot, F means take a step forward, L means

You are given an input string that controls the movement of a robot, "F" means take a step forward, "L" means turn 90 degrees to the left and
"R" means turn 90 degrees to the right. E.g."FLF" moves the robot one step forward, then turns it left by 90 degrees, then moves the robot one step forward. Write a function that returns the minimum number of commands that the robot needs to return to its starting
point after following all the input commands. You should ignore any characters that are not capital F, L, or R. Hint: you may wish to track the robots position using (X,Y) coordinates, assuming it starts at (0,0).
For example:
*"RF" returns 3(robot must turn twice and move forward one step (eg."RRF")
*"LFRFRFR" returns 1(robot must step forward to return)
*"FxLxLxFx" returns 0(robot is already back at its starting point)
*[execution time limit]4 seconds (js)
*[memory limit]1 GB
*[input] string directionsThe directions for the robot
*[output] integer

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Microsoft Visual Basic 2008 Comprehensive Concepts And Techniques

Authors: Gary B. Shelly, Corinne Hoisington

1st Edition

1423927168, 978-1423927167

More Books

Students also viewed these Databases questions

Question

Learn the principles of the scientific method

Answered: 1 week ago