✅Beats 100% Frequency Array  || 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 parts (nums1 and nums2), eac
# Intuition\nThe goal of the `isPossibleToSplit` function is to determine whether it is possible to split the given array `nums` into two parts (`nums1` and `nums2`), each containing distinct elements.\n\n# Approach\n1. **Frequency Array:**\n    The code utilizes an array (`elementFrequency`) to store the frequency of each element in the given array `nums`. The array size is set to 101 to accommodate values in the range [1, 100].\n\n2. **Populating the Frequency Array:**\n    It iterates through the array `nums` and increments the corresponding count in the `elementFrequency` array for each element encountered.\n\n3. **Checking Distinct Elements:**\n    During the iteration, it checks if the frequency of any element becomes greater than 2. If so, it immediately returns `false` as it indicates non-distinct elements.\n\n4. **Result:**\n    If no element exceeds a frequency of 2, the function returns `true`, indicating that it is possible to split the array into two parts with distinct elements.\n\n# Complexity\n- Time complexity:\n\n    The function iterates through the entire `nums` array once, updating the frequency array. Therefore, the time complexity is O(nums.length).\n\n- Space complexity:\n\n    The space complexity is O(1) as it uses a fixed-size array      (`elementFrequency`) regardless of the input size.\n\n# Code\n```java []\nclass Solution {\n    public boolean isPossibleToSplit(int[] nums) {\n        // Array to store the frequency of each element in the range [1, 100]\n        int[] elementFrequency = new int[101];\n        \n        // Populating the frequency array\n        for (int num : nums) {\n            elementFrequency[num]++;\n            \n            // If any element frequency exceeds 2, it\'s not possible to split\n            if (elementFrequency[num] > 2) {\n                return false;\n            }\n        }\n        \n        // If no element frequency exceeds 2, it\'s possible to split\n        return true;\n    }\n}\n\n```\n```python []\nclass Solution(object):\n    def isPossibleToSplit(self, nums):\n        element_frequency = [0] * 101\n        \n        for num in nums:\n            element_frequency[num] += 1\n\n            # If any element frequency exceeds 2, it\'s not possible to split\n            if element_frequency[num] > 2:\n                return False\n        \n        # If no element frequency exceeds 2, it\'s possible to split\n        return True\n        \n```\n```C++ []\nclass Solution {\npublic:\n    bool isPossibleToSplit(vector<int>& nums) {\n        // Array to store the frequency of each element in the range [1, 100]\n        int elementFrequency[101] = {0};\n        \n        // Populating the frequency array\n        for (int num : nums) {\n            elementFrequency[num]++;\n            \n            // If any element frequency exceeds 2, it\'s not possible to split\n            if (elementFrequency[num] > 2) {\n                return false;\n            }\n        }\n```\n```javascript []\n/**\n * @param {number[]} nums\n * @return {boolean}\n */\nvar isPossibleToSplit = function(nums) {\n    const elementFrequency = new Array(101).fill(0);\n        \n        // Populating the frequency array\n        for (const num of nums) {\n            elementFrequency[num]++;\n            \n            // If any element frequency exceeds 2, it\'s not possible to split\n            if (elementFrequency[num] > 2) {\n                return false;\n            }\n        }\n        \n        // If no element frequency exceeds 2, it\'s possible to split\n        return true;\n\n        return true;\n};\n```\n\nIf you found this content helpful, consider giving it an **upvote** and share your thoughts in the comments.\n
['Array', 'Python', 'C++', 'Java', 'Python3', 'JavaScript']