Tap here to switch tabs
Problem
Submissions

Problem: Maximum Distance Between Unequal Words in Array II

Maximum Distance Between Unequal Words in Array II asks you to find the greatest span between two array positions containing different strings, counting both endpoints, or return zero if all match.

Statement

You are given an array of strings words.

The distance between two indices i and j (i≤ji \leq j) is defined as j−i+1j - i + 1.

Return the maximum distance between any two indices i and j such that words[i] \neq words[j]. If no two unequal strings exist in words, return 00.

Constraints:

  • 1≤1 \leq words.length ≤105\leq 10^5

  • 1≤1 \leq words[i].length ≤10\leq 10

  • words[i] consists only of lowercase English letters.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Maximum Distance Between Unequal Words in Array II

Maximum Distance Between Unequal Words in Array II asks you to find the greatest span between two array positions containing different strings, counting both endpoints, or return zero if all match.

Statement

You are given an array of strings words.

The distance between two indices i and j (i≤ji \leq j) is defined as j−i+1j - i + 1.

Return the maximum distance between any two indices i and j such that words[i] \neq words[j]. If no two unequal strings exist in words, return 00.

Constraints:

  • 1≤1 \leq words.length ≤105\leq 10^5

  • 1≤1 \leq words[i].length ≤10\leq 10

  • words[i] consists only of lowercase English letters.