Minimum Consecutive Cards to Pick Up LeetCode solution in Java
1class Solution {2public int minimumCardPickup(int[] cards) {3Map<Integer, Integer> map = new HashMap<>();4int min = Integer.MAX_VALUE;5for (int i = 0; i < cards.length; i++) {6if (map.containsKey(cards[i]))7min =8Math.min(9i - map.get(cards[i]) + 1,10min); // Check if the difference in indices is smaller than minimum11map.put(cards[i], i); // Update the last found index of the card12}13return min == Integer.MAX_VALUE ? -1 : min; // Repetition found or not14}15}