Tap here to switch tabs
Problem
Submissions

Problem: Minimum Distance Between Three Equal Elements I

Try to solve the Minimum Distance Between Three Equal Elements I problem.

Statement

Given an integer array nums, a triplet of indices (i, j, k) is called a good triplet if i<j<ki < j < k and nums[i] == nums[j] == nums[k].

The distance of a good triplet (i, j, k) is defined as ∣i−j∣+∣j−k∣+∣k−i∣|i - j| + |j - k| + |k - i|.

Return the minimum distance among all good triplets in nums. If no good triplet exists, return −1-1.

Constraints:

  • 1≤n==1 \leq n == nums.length ≤100\leq 100

  • 1≤1 \leq nums[i] ≤n\leq n

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Distance Between Three Equal Elements I

Try to solve the Minimum Distance Between Three Equal Elements I problem.

Statement

Given an integer array nums, a triplet of indices (i, j, k) is called a good triplet if i<j<ki < j < k and nums[i] == nums[j] == nums[k].

The distance of a good triplet (i, j, k) is defined as ∣i−j∣+∣j−k∣+∣k−i∣|i - j| + |j - k| + |k - i|.

Return the minimum distance among all good triplets in nums. If no good triplet exists, return −1-1.

Constraints:

  • 1≤n==1 \leq n == nums.length ≤100\leq 100

  • 1≤1 \leq nums[i] ≤n\leq n