Ctrl K

Farthest From the Start

Easy
A robot stands at point 0 on a number line and runs the program moves, a string of the characters L, R and _. Every character is a step of length 1: - L always goes left; - R always goes right; - _ goes whichever way you choose. Return the greatest distance from point 0 the robot can end up at once the whole program has run.
Example 1
moves='R__L_R' → 4

Turning all three free steps to the right gives R R R L R R, which ends at point 4.

Example 2
moves='LLR_' → 2

The fixed steps end at -1; taking the free step left reaches -2.

Example 3
moves='LR' → 0
Constraints
  • 1 ≤ len(moves) ≤ 50
  • moves contains only the characters L, R and _
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsNote From Clipped Letters EasyFirst One-Off Letter EasyWords Heard Only Once EasyWords From Letter Tiles EasyBalloon Signs From Letters Easy
loading Python…
Input
moves='R__L_R'
Expected
4

Run checks the first 3 tests in your browser. Submit checks all 152 tests on the server, hidden ones included.