1class Solution:2def maxDistance(self, colors: List[int]) -> int:3# first pass4l, r = 0, len(colors) - 15dist = 067while r > l:8if colors[r] != colors[l]:9dist = r - l10# slight performance increase, break out if you find it11# because it can't get bigger than this12break13r -= 11415# second pass, backwards16l, r = 0, len(colors) - 117while r > l:18if colors[r] != colors[l]:19dist = max(dist, r - l)20break21l += 12223return dist