Minimum Consecutive Cards to Pick Up Problem
Minimum Consecutive Cards to Pick Up Problem — ExecCode Easy DSA Practice
Solve the Minimum Consecutive Cards to Pick Up problem on ExecCode. Free online easy DSA practice in Sliding Window. Write and run code in Java, C++, Python — no signup required to run.
Problem description
Description You are given an integer array cards where cards[i] represents the value of the i^th card. Your task is to compute the required answer and return the minimum number of consecutive cards you have to pick up to have a pair of matching cards among the picked cards. A pair of cards are matching if the cards have the same value. If it is impossible to have matching cards, return -1.
Examples
Input {"cards": [3, 4, 2, 3, 4]}; Output 4. Input {"cards": [1, 2, 3, 4]}; Output -1. Input {"cards": [1, 2, 3, 1, 4, 5, 6]}; Output 4
Constraints
1 <= cards.length <= 10^5 0 <= cards[i] <= 10^6
Practice Minimum Consecutive Cards to Pick Up free on ExecCode. Browse DSA problems, topic map, and placement guides.