Tap here to switch tabs
Problem
Submissions

Problem: Two Furthest Houses With Different Colors

med
30 min
Try to solve the Two Furthest Houses With Different Colors problem.

Statement

There are nn houses lined up on a street, with each house painted in a certain color. You are given a 00 indexed integer array colors of length nn, where colors[i] represents the color of the iextthi^{ ext{th}} house.

The distance between the iextthi^{ ext{th}} house and the jextthj^{ ext{th}} house is defined as ∣i−j∣|i - j|.

Return the maximum possible distance between two houses that have different colors.

Constraints:

  • n == colors.length

  • 2≤n≤1002 \leq n \leq 100

  • 0≤0 \leq colors[i] ≤100\leq 100

  • At least two houses have different colors in the generated test data.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Two Furthest Houses With Different Colors

med
30 min
Try to solve the Two Furthest Houses With Different Colors problem.

Statement

There are nn houses lined up on a street, with each house painted in a certain color. You are given a 00 indexed integer array colors of length nn, where colors[i] represents the color of the iextthi^{ ext{th}} house.

The distance between the iextthi^{ ext{th}} house and the jextthj^{ ext{th}} house is defined as ∣i−j∣|i - j|.

Return the maximum possible distance between two houses that have different colors.

Constraints:

  • n == colors.length

  • 2≤n≤1002 \leq n \leq 100

  • 0≤0 \leq colors[i] ≤100\leq 100

  • At least two houses have different colors in the generated test data.