Skip to content

Practice Minimum Consecutive Cards to Pick Up

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#2260
LeetCode Problem

Minimum Consecutive Cards to Pick Up

Problem Statement

You are given an integer array cards where cards[i] represents the value of the ith card. A pair of cards are matching if the cards have the same value. Return the minimum number of consecutive cards you have to pick up to have a pair of matching cards among the picked cards. If it is impossible to have matching cards, return -1.

Source: Minimum Consecutive Cards to Pick Up on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
cards = [3,4,2,3,4,7]
Output
4

# Example 2

Input
cards = [1,0,5,3]
Output
-1

Constraints

1 <= cards.length <= 10^5
0 <= cards[i] <= 10^6

Related LeetCode Problems

Practice more problems similar to Minimum Consecutive Cards to Pick Up.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.