bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 838. Push Dominoes

838. Push Dominoes

Leetcode Solutions

Approach #: Calculate Force

  1. Initialize two arrays forces to store the forces exerted on each domino from the left and the right.
  2. Perform a left-to-right pass to calculate the forces exerted by 'R' dominoes. Reset the force to n (the length of the dominoes string) when an 'R' is encountered and decrease it by 1 for each step to the right.
  3. Perform a right-to-left pass to calculate the forces exerted by 'L' dominoes. Reset the force to -n when an 'L' is encountered and increase it by 1 for each step to the left.
  4. After both passes, iterate over the forces array to determine the final state of each domino based on the net force.
  5. Construct the result string based on the forces and return it.
UML Thumbnail

Approach #: Adjacent Symbols

Ask Question

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

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...