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

Leetcode Problem 1184. Distance Between Bus Stops

1184. Distance Between Bus Stops

Leetcode Solutions

Calculate Clockwise and Counter-Clockwise Distances

  1. Initialize two variables clockwiseDistance and totalDistance to 0.
  2. Loop through the distance array to calculate totalDistance.
  3. Loop from start to destination to calculate clockwiseDistance.
  4. Calculate counterClockwiseDistance as totalDistance - clockwiseDistance.
  5. Return the minimum of clockwiseDistance and counterClockwiseDistance.
UML Thumbnail

Iterate Over Array to Find Distances

Ask Question

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

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...