364. Two Furthest Houses With Different Colors

EasyGreedy

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.

Examples

Input: [1,1,1,6,1,1,1]

Output: 3

Explanation: Public test case for Two Furthest Houses With Different Colors

Constraints

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

Run checks all cases above. Submit evaluates all test cases.