Skip to content

Practice Two Furthest Houses With Different Colors

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Easy#2078
LeetCode Problem

Two Furthest Houses With Different Colors

Problem Statement

There are n houses evenly lined up on the street, and each house is beautifully painted. You are given a 0-indexed integer array colors of length n, where colors[i] represents the color of the ith house. Return the maximum distance between two houses with different colors. The distance between the ith and jth houses is abs(i - j), where abs(x) is the absolute value of x.

Source: Two Furthest Houses With Different Colors on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
colors = [1,1,1,6,1,1,1]
Output
3

# Example 2

Input
colors = [1,8,3,8,3]
Output
4

# Example 3

Input
colors = [0,1]
Output
1

Constraints

n == colors.length
2 <= n <= 100
0 <= colors[i] <= 100
Test data are generated such that at least two houses have different colors.

Related LeetCode Problems

Practice more problems similar to Two Furthest Houses With Different Colors.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.