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.
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
colors = [1,1,1,6,1,1,1]
3
# Example 2
colors = [1,8,3,8,3]
4
# Example 3
colors = [0,1]
1
Constraints
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.