C++ 100% Fast | Easy Step By Step Explanation
Intuition\n1. Frequency Counting: The problem revolves around determining if elements in the array can be divided into two halves with distinct elements. This s
# Intuition\n1. **Frequency Counting:** The problem revolves around determining if elements in the array can be divided into two halves with distinct elements. This suggests using a data structure to track element frequencies.\n2. **Unique Element Requirement:** The key constraint is that each element can appear at most twice in the entire array to allow for distinct halves.\n\n# Approach\n1. **Count Frequencies:** Use a unordered_map to efficiently count the occurrences of each element in nums.\n2. **Check for Impossible Cases:**\n    - If the number of unique elements is less than half the array length, it\'s impossible to form distinct halves.\n    - If any element appears more than twice, it cannot be placed in distinct halves.\n3. **Return Splitting Possibility:** If no impossible cases are encountered, a valid split is possible.\n\n# Complexity\n- Time complexity: **O(n)**\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: **O(n)**\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    bool isPossibleToSplit(vector<int>& nums) {\n        unordered_map<int, int>mp;\n        for(auto it:nums){\n            mp[it]++;\n        }\n        int unique = mp.size();\n        for(auto it:mp){\n            if(it.second>2){\n                return false;\n            }\n        }\n        return true;\n    }\n};\n```\n\n![Please Upvote2.jpeg](https://assets.leetcode.com/users/images/184e50db-2207-4c36-ba4c-333c8183f0fc_1708833733.676199.jpeg)\n
['Array', 'Ordered Map', 'C++']