Leetcode Problem 2078. Two Furthest Houses With Different Colors

2078. Two Furthest Houses With Different Colors

Leetcode Solutions

Two Pointers Approach

  1. Initialize two variables maxDistFromStart and maxDistFromEnd to 0.
  2. Iterate from the start of the array and find the distance to the last house with a different color.
  3. Iterate from the end of the array and find the distance to the first house with a different color.
  4. The maximum distance is the maximum of maxDistFromStart and maxDistFromEnd.
  5. Return the maximum distance.
UML Thumbnail

Brute Force Approach

Ask Question

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

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...