Class Solution

  • All Implemented Interfaces:

    
    public final class Solution
    
                        

    2833 - Furthest Point From Origin.

    Easy

    You are given a string moves of length n consisting only of characters 'L', 'R', and '_'. The string represents your movement on a number line starting from the origin 0.

    In the <code>i<sup>th</sup></code> move, you can choose one of the following directions:

    • move to the left if moves[i] = 'L' or moves[i] = '_'

    • move to the right if moves[i] = 'R' or moves[i] = '_'

    Return the distance from the origin of the furthest point you can get to after n moves.

    Example 1:

    Input: moves = "L\_RL\_\_R"

    Output: 3

    Explanation: The furthest point we can reach from the origin 0 is point -3 through the following sequence of moves "LLRLLLR".

    Example 2:

    Input: moves = "\_R\_\_LL\_"

    Output: 5

    Explanation: The furthest point we can reach from the origin 0 is point -5 through the following sequence of moves "LRLLLLL".

    Example 3:

    Input: moves = "\_\_\_\_\_\_\_"

    Output: 7

    Explanation: The furthest point we can reach from the origin 0 is point 7 through the following sequence of moves "RRRRRRR".

    Constraints:

    • 1 &lt;= moves.length == n &lt;= 50

    • moves consists only of characters 'L', 'R' and '_'.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
      Solution()
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final Integer furthestDistanceFromOrigin(String moves)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait