class Solution {
public int maxOperations(int[] nums, int k) {
HashMap<Integer, Integer> map = new HashMap<>();
int count = 0;
for (int i = 0; i < nums.length; i++) {
int current = nums[i];
int complement = k - current;
if (map.getOrDefault(complement, 0) > 0) {
// remove complement from the map
map.put(complement, map.get(complement) - 1);
count++;
} else {
// add current element in the map
map.put(current, map.getOrDefault(current, 0) + 1);
}
}
return count;
}
}
class Solution {
public int concatenatedBinary(int n) {
final int MOD = 1000000007;
int length = 0; // bit length of addends
long result = 0; // long accumulator
for (int i = 1; i <= n; i++) {
// when meets power of 2, increase the bit length
if ((i & (i - 1)) == 0) {
length++;
}
result = ((result << length) | i) % MOD;
}
return (int) result;
}
}