Maximum Number of Pairs in Array LeetCode solution in C++
1class Solution {2public:3// store the frequency of each of the number in the map and4// then return the answer as sum all the values dividing 2 and5// sum all by taking reminder of 26vector<int> numberOfPairs(vector<int> &nums) {7unordered_map<int, int> mp;8for (auto i : nums) mp[i]++;9int c1 = 0, c2 = 0;10for (auto m : mp) {11c1 += m.second / 2;12c2 += m.second % 2;13}14return {c1, c2};15}16};