You are given an integer array nums and an integer k. In one operation you may remove two indices i < j if nums[i] + nums[j] == k; each index can be used at most once. Return the maximum number of operations you can perform. Design an O(n) or O(n log n) solution, discuss space–time trade-offs, and provide code in C, C++, Java, or JavaScript.