Tap here to switch tabs
Problem
Submissions

Problem: Minimum Absolute Difference Between Two Values

Minimum Absolute Difference Between Two Values asks for the smallest index distance between a 1 and a 2 in an array of zeros, ones, and twos, or -1 if either is missing.

Statement

Given an integer array nums consisting only of the integers 00, 11, and 22, find the minimum absolute difference between the indices i and j such that nums[i] is equal to 11 and nums[j] is equal to 22.

Return the minimum value of ∣i−j∣|i - j| among all such pairs. If the array does not contain both 11 and 22, return −1-1.

Constraints:

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

  • 0≤0 \leq nums[i] ≤2\leq 2

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Absolute Difference Between Two Values

Minimum Absolute Difference Between Two Values asks for the smallest index distance between a 1 and a 2 in an array of zeros, ones, and twos, or -1 if either is missing.

Statement

Given an integer array nums consisting only of the integers 00, 11, and 22, find the minimum absolute difference between the indices i and j such that nums[i] is equal to 11 and nums[j] is equal to 22.

Return the minimum value of ∣i−j∣|i - j| among all such pairs. If the array does not contain both 11 and 22, return −1-1.

Constraints:

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

  • 0≤0 \leq nums[i] ≤2\leq 2