|
| 1 | +/** |
| 2 | + * [2260] Minimum Consecutive Cards to Pick Up |
| 3 | + * |
| 4 | + * You are given an integer array cards where cards[i] represents the value of the i^th card. A pair of cards are matching if the cards have the same value. |
| 5 | + * 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. |
| 6 | + * |
| 7 | + * Example 1: |
| 8 | + * |
| 9 | + * Input: cards = [3,4,2,3,4,7] |
| 10 | + * Output: 4 |
| 11 | + * Explanation: We can pick up the cards [3,4,2,3] which contain a matching pair of cards with value 3. Note that picking up the cards [4,2,3,4] is also optimal. |
| 12 | + * |
| 13 | + * Example 2: |
| 14 | + * |
| 15 | + * Input: cards = [1,0,5,3] |
| 16 | + * Output: -1 |
| 17 | + * Explanation: There is no way to pick up a set of consecutive cards that contain a pair of matching cards. |
| 18 | + * |
| 19 | + * |
| 20 | + * Constraints: |
| 21 | + * |
| 22 | + * 1 <= cards.length <= 10^5 |
| 23 | + * 0 <= cards[i] <= 10^6 |
| 24 | + * |
| 25 | + */ |
| 26 | +pub struct Solution {} |
| 27 | + |
| 28 | +// problem: https://leetcode.com/problems/minimum-consecutive-cards-to-pick-up/ |
| 29 | +// discuss: https://leetcode.com/problems/minimum-consecutive-cards-to-pick-up/discuss/?currentPage=1&orderBy=most_votes&query= |
| 30 | + |
| 31 | +// submission codes start here |
| 32 | + |
| 33 | +impl Solution { |
| 34 | + pub fn minimum_card_pickup(cards: Vec<i32>) -> i32 { |
| 35 | + 0 |
| 36 | + } |
| 37 | +} |
| 38 | + |
| 39 | +// submission codes end |
| 40 | + |
| 41 | +#[cfg(test)] |
| 42 | +mod tests { |
| 43 | + use super::*; |
| 44 | + |
| 45 | + #[test] |
| 46 | + #[ignore] |
| 47 | + fn test_2260_example_1() { |
| 48 | + let cards = vec![3, 4, 2, 3, 4, 7]; |
| 49 | + |
| 50 | + let result = 4; |
| 51 | + |
| 52 | + assert_eq!(Solution::minimum_card_pickup(cards), result); |
| 53 | + } |
| 54 | + |
| 55 | + #[test] |
| 56 | + #[ignore] |
| 57 | + fn test_2260_example_2() { |
| 58 | + let cards = vec![1, 0, 5, 3]; |
| 59 | + |
| 60 | + let result = -1; |
| 61 | + |
| 62 | + assert_eq!(Solution::minimum_card_pickup(cards), result); |
| 63 | + } |
| 64 | +} |
0 commit comments