2078. Two Furthest Houses With Different Colors
On This Page
class Solution:
def maxDistance(self, colors: List[int]) -> int:
n = len(colors)
if colors[0] != colors[-1]:
return n - 1
i, j = 1, n - 2
while colors[i] == colors[0]:
i += 1
while colors[j] == colors[0]:
j -= 1
return max(n - i - 1, j)