✅HashMap solution || Split the array|| Simple solution in Java, C++, Python & javascript
Intuition\nThe goal of the isPossibleToSplit function is to determine whether it is possible to split the given array nums into two distinct parts (nums1 and nu
# Intuition\nThe goal of the `isPossibleToSplit` function is to determine whether it is possible to split the given array `nums` into two distinct parts (`nums1` and `nums2`), each containing distinct elements.\n\n# Approach\n1. **Frequency Map:**\n    The code uses a HashMap (`map`) to keep track of the frequency of each element in the array.\n\n2. **Populating the Frequency Map:**\n    It iterates through the array and updates the frequency of each element in the map.\n\n3. **Checking Distinct Elements:**\n    After creating the frequency map, it iterates through the keys of the map and checks if any element has a frequency greater than 2. If so, it returns `false` since it is not possible to have two distinct arrays.\n\n4. **Result:**\n    If no element has a frequency greater than 2, it returns `true`, indicating that it is possible to split the array into two parts with distinct elements.\n\n# Complexity\n- Time complexity:\n  - The first loop to populate the frequency map runs in O(nums.length) time.\n  - The second loop to check frequencies runs in O(unique elements) time.\n  - Therefore, the overall time complexity is O(nums.length + unique elements).\n\n- Space complexity:\n The space complexity is O(unique elements) as it stores the frequency of each unique element in the map.\n\n```java []\nclass Solution {\n    // Function to check if it\'s possible to split the array into two parts\n    public boolean isPossibleToSplit(int[] nums) {\n        // HashMap to store the frequency of each element in the array\n        HashMap<Integer, Integer> map = new HashMap<>();\n        \n        // Populating the frequency map\n        for (int i = 0; i < nums.length; i++) {\n            map.put(nums[i], map.getOrDefault(nums[i], 0) + 1);\n        }\n        \n        // Checking distinct elements in the frequency map\n        for (int i : map.keySet()) {\n            if (map.get(i) > 2)\n                return false;\n        }\n        \n        // If no element has a frequency greater than 2, return true\n        return true;\n    }\n}\n```\n```python []\nclass Solution(object):\n    def isPossibleToSplit(self, nums):\n        mapping = {}\n\n        for num in nums:\n            mapping[num] = mapping.get(num, 0) + 1\n\n        for count in mapping.values():\n            if count > 2:\n                return False\n\n        return True\n```\n```C++ []\nclass Solution {\npublic:\n    bool isPossibleToSplit(vector<int>& nums) {\n        unordered_map<int, int> map;\n\n        for (int i = 0; i < nums.size(); i++) {\n            map[nums[i]] = map[nums[i]] + 1;\n        }\n\n        for (auto& pair : map) {\n            if (pair.second > 2) {\n                return false;\n            }\n        }\n\n        return true;\n    }\n};\n```\n```javascript []\n/**\n * @param {number[]} nums\n * @return {boolean}\n */\nvar isPossibleToSplit = function(nums) {\n    const map = new Map();\n\n        for (const num of nums) {\n            map.set(num, (map.get(num) || 0) + 1);\n        }\n\n        for (const count of map.values()) {\n            if (count > 2) {\n                return false;\n            }\n        }\n\n        return true;\n};\n```\nIf you found this content helpful, consider giving it an **upvote** and share your thoughts in the comments.
['Array', 'Hash Table', 'Python', 'C++', 'Java', 'Python3', 'JavaScript']