Leetcode Problem 2833. Furthest Point From Origin

2833. Furthest Point From Origin

Leetcode Solutions

Counting Moves and Maximizing Distance

  1. Initialize three counters: countL, countR, and count_ to zero.
  2. Iterate through each character in the moves string.
    • Increment countL if the character is 'L'.
    • Increment countR if the character is 'R'.
    • Increment count_ if the character is '_'.
  3. Calculate the initial distance from the origin by taking the absolute difference between countL and countR.
  4. Add count_ to the initial distance to get the furthest distance.
  5. Return the furthest distance.
UML Thumbnail

Simulate Moves with Direction Preference

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...