Tap here to switch tabs
Problem
Submissions

Problem: Minimum Consecutive Cards to Pick Up

med
30 min
Try to solve the Minimum Consecutive Cards to Pick Up problem.

Statement

You are given an integer array cards representing a sequence of cards.

Find the minimum number of consecutive cards you must pick up such that the selected sequence contains at least one pair of matching cards with the same value.

Return the minimum length of such a consecutive subarray. If it is impossible to find any matching pair, return −1-1.

Constraints:

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

  • 0≤0 \leq cards[i] ≤106\leq 10^6

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Consecutive Cards to Pick Up

med
30 min
Try to solve the Minimum Consecutive Cards to Pick Up problem.

Statement

You are given an integer array cards representing a sequence of cards.

Find the minimum number of consecutive cards you must pick up such that the selected sequence contains at least one pair of matching cards with the same value.

Return the minimum length of such a consecutive subarray. If it is impossible to find any matching pair, return −1-1.

Constraints:

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

  • 0≤0 \leq cards[i] ≤106\leq 10^6