package leetcode;

import java.util.HashMap;
import java.util.Map;

/**
 * https://leetcode.com/problems/max-number-of-k-sum-pairs/
 */
public class Problem1679 {
    public int maxOperations(int[] nums, int k) {
        Map</* value */ Integer, /* count */ Integer> map = new HashMap<>();
        for (int num : nums) {
            map.put(num, map.getOrDefault(num, 0) + 1);
        }
        return 0;
    }

    public static void main(String[] args) {
        Problem1679 prob = new Problem1679();
        System.out.println(prob.maxOperations(new int[]{1,2,3,4}, 5)); // 2
        System.out.println(prob.maxOperations(new int[]{3,1,3,4,3}, 6)); // 1
    }
}

@@ -392,22 +392,28 @@
     
-return
+int answer =
  0;%0A    
 %7D%0A%0A 
@@ -412,255 +412,931 @@
     
+ 
-%7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        Problem1679 prob = new Problem1679();%0A        System.out.println(prob.maxOperations(new int%5B%5D%7B1,2,3,4%7D, 5)); // 2%0A        System.out.println(prob.maxOperations(new int%5B%5D%7B3,1,3,4,3%7D, 6)); // 1
+   for (int a : nums) %7B%0A            int countA = map.getOrDefault(a, 0);%0A            if (countA == 0) %7B%0A                continue;%0A            %7D%0A            int b = k - a;%0A            int countB = map.getOrDefault(b, 0);%0A            if (a == b) %7B%0A                if (countB %3E 1) %7B%0A                    update(map, a);%0A                    update(map, b);%0A                    answer++;%0A                %7D%0A            %7D else %7B%0A                if (countB %3E 0) %7B%0A                    update(map, a);%0A                    update(map, b);%0A                    answer++;%0A                %7D%0A            %7D%0A        %7D%0A        return answer;%0A    %7D%0A%0A    private static void update(Map%3CInteger, Integer%3E map, int val) %7B%0A        int count = map.getOrDefault(val, 0);%0A        if (count == 0) %7B%0A            return;%0A        %7D%0A        if (count - 1 == 0) %7B%0A            map.remove(val);%0A        %7D else %7B%0A            map.put(val, count - 1);%0A        %7D
 %0A   

Solve problem 1679