diff --git "a/LiiNi-coder/202512/09 PGM \355\225\240\354\235\270 \355\226\211\354\202\254.md" "b/LiiNi-coder/202512/09 PGM \355\225\240\354\235\270 \355\226\211\354\202\254.md" new file mode 100644 index 00000000..2649a647 --- /dev/null +++ "b/LiiNi-coder/202512/09 PGM \355\225\240\354\235\270 \355\226\211\354\202\254.md" @@ -0,0 +1,48 @@ +```java +import java.util.*; + +class Solution { + private static HashMap wordsIndex; + + public int solution(String[] wants, int[] number, String[] discounts) { + int answer = 0; + wordsIndex = new HashMap(); + int i = 0; + for(String want : wants){ + wordsIndex.put(want, i++); + } + int[] counts = new int[wants.length]; + + ArrayDeque q = new ArrayDeque(); + String polled; + for(String discount : discounts){ + if(wordsIndex.containsKey(discount)){ + counts[wordsIndex.get(discount)]++; + } + q.offer(discount); + if(q.size() > 10){ + polled = q.poll(); + if(wordsIndex.containsKey(polled)){ + counts[wordsIndex.get(polled)]--; + } + } + + if(q.size() == 10){ + boolean ok = true; + for(int k=0; k