Ctrl K

Farthest Differently Painted Houses

Easy
Houses stand along a street at equal intervals, and paint[i] is the color code of house i. The distance between houses i and j is |i - j|. Find the largest distance between two houses painted in different colors. The street is guaranteed to have at least two different colors.
Example 1
paint=[3, 3, 5, 3, 3, 3] → 3

The only house of another color stands at position 2. The farthest house from it is the last one: 5 - 2 = 3.

Example 2
paint=[4, 1, 1, 4, 2] → 4

The first and the last houses have different colors (4 and 2), and the distance between them is 4, the largest possible.

Constraints
  • 2 ≤ len(paint) ≤ 100
  • 0 ≤ paint[i] ≤ 100
  • Not all houses share one color
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsCake Slices for Guests EasyStrength of the Weaker Partner EasyPlanting Along a Garden Row EasyMaking Change at the Kiosk EasyRise and Fall Lineup Easy
loading Python…
Input
paint=[3, 3, 5, 3, 3, 3]
Expected
3

Run checks the first 3 tests in your browser. Submit checks all 91 tests on the server, hidden ones included.