Tap here to switch tabs
Problem
Submissions

Problem: Two Furthest Houses With Different Colors

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 ithi^{ th} house.

The distance between the ithi^{ th} house and the jthj^{ 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

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 ithi^{ th} house.

The distance between the ithi^{ th} house and the jthj^{ 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.