Efficient Solution: Beats 90% in Runtime
Intuition\nThe first thought is to check if every integer in the array appears exactly twice. If any integer appears more than twice or if the total number of e
## Intuition\nThe first thought is to check if every integer in the array appears exactly twice. If any integer appears more than twice or if the total number of elements is odd, it would be impossible to form pairs.\n\n## Approach\n1. **Check array length:** If the length of the array is odd, return `false` since an odd number of elements cannot form pairs.\n2. **Count occurrences:** Use a map (or hash table) to count the occurrences of each integer in the array.\n3. **Check counts:** Traverse the map to ensure that each integer appears exactly twice. If any integer appears more than twice, return `false`.\n4. **Return true:** If all checks pass, return `true` indicating that it is possible to split the array into pairs.\n\n## Complexity\n- **Time complexity:** \\(O(n)\\), where \\(n\\) is the number of elements in the array. This is because we traverse the array once to count the occurrences and then traverse the map to check the counts.\n- **Space complexity:** \\(O(n)\\), where \\(n\\) is the number of distinct elements in the array. This is because we store counts for each distinct element in the map.\n\n## Code\nHere is the complete implementation of the solution:\n\n```cpp\nclass Solution {\npublic:\n    bool isPossibleToSplit(vector<int>& nums) {\n        // Check if the number of elements is odd\n        if (nums.size() % 2 != 0) {\n            return false;\n        }\n        \n        // Count occurrences of each integer\n        std::map<int, int> my_map;\n        for (int i: nums) {\n            my_map[i]++;\n            // If any integer appears more than twice, return false\n            if (my_map[i] > 2) {\n                return false;\n            }\n        }\n        \n        // If all integers appear exactly twice, return true\n        return true;\n    }\n};\n```\n\nThis code ensures that we can only split the array into pairs if every integer appears exactly twice. If the conditions are not met, it returns `false`.
['C++']