Class Solution
java.lang.Object
g2201_2300.s2260_minimum_consecutive_cards_to_pick_up.Solution
2260 - Minimum Consecutive Cards to Pick Up.<p>Medium</p>
<p>You are given an integer array <code>cards</code> where <code>cards[i]</code> represents the <strong>value</strong> of the <code>i<sup>th</sup></code> card. A pair of cards are <strong>matching</strong> if the cards have the <strong>same</strong> value.</p>
<p>Return <em>the <strong>minimum</strong> number of <strong>consecutive</strong> cards you have to pick up to have a pair of <strong>matching</strong> cards among the picked cards.</em> If it is impossible to have matching cards, return <code>-1</code>.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> cards = [3,4,2,3,4,7]</p>
<p><strong>Output:</strong> 4</p>
<p><strong>Explanation:</strong> We can pick up the cards [3,4,2,3] which contain a matching pair of cards with value 3.</p>
<p>Note that picking up the cards [4,2,3,4] is also optimal.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> cards = [1,0,5,3]</p>
<p><strong>Output:</strong> -1</p>
<p><strong>Explanation:</strong> There is no way to pick up a set of consecutive cards that contain a pair of matching cards.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= cards.length <= 10<sup>5</sup></code></li>
<li><code>0 <= cards[i] <= 10<sup>6</sup></code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
minimumCardPickup
public int minimumCardPickup(int[] cards)
-