Beats 100% | Detailed Solution | Java, C, C++, JavaScript, Python ✅✅
Its Easy, Just read \n# You can do it\n# Approach\n Describe your approach to solving the problem. \n1. int[] data = new int[101]; creates an integer array name
# Its Easy, Just read \n# You can do it\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. int[] data = new int[101]; creates an integer array named data with a size of 101. This array will be used to store the frequency of each number in the input array nums.\n2. for (int i : nums) iterates over each element i in the input array nums.\ndata[i]++; increments the count of the current element i in the data array. This effectively tracks how many times each number appears in nums.\n3. if (data[i] > 2) { return false; } checks if the count of any element in data becomes greater than 2. This condition ensures that no number appears more than twice in the input array. If this condition is violated, the method immediately returns false, indicating that splitting is not possible.\n4. If the loop completes without encountering any violations in the if condition, it means that no number appears more than twice in nums. Therefore, the method returns true, signifying that splitting the array 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# Please Upvote !\u2705\u2705\n# Code\n``` java []\nclass Solution {\n    public boolean isPossibleToSplit(int[] nums) {\n        int[] data = new int[101];\n        \n        for(int i : nums){\n            data[i]++;\n            if(data[i]>2)   return false;\n        }\n        return true;\n    }\n}\n```\n```C []\nbool isPossibleToSplit(int* nums, int numsSize) {\n    int data[101] = {0};\n        \n        for(int i=0;i<numsSize;i++){\n            data[nums[i]]++;\n            if(data[nums[i]]>2)   return false;\n        }\n        return true;\n}\n```\n```C++ []\nclass Solution {\npublic:\n    bool isPossibleToSplit(vector<int>& nums) {\n        int data[101] = {0};\n        \n        for(int i=0;i<nums.size();i++){\n            data[nums[i]]++;\n            if(data[nums[i]]>2)   return false;\n        }\n        return true;\n    }\n};\n```\n```JavaScript []\n/**\n * @param {number[]} nums\n * @return {boolean}\n */\nvar isPossibleToSplit = function(nums) {\n    const data = new Array(101).fill(0); \n\n    for (const i of nums) {\n        data[i]++; \n        if (data[i] > 2)  return false; \n    }\n\n    return true; \n};\n```\n```Python []\nclass Solution:\n    def isPossibleToSplit(self, nums: List[int]) -> bool:\n        data = [0] * 101  \n\n        for i in nums:\n            data[i] += 1  \n            if data[i] > 2: return False  \n\n        return True\n```\n
['Hash Table', 'Stack', 'Ordered Map', 'C', 'Suffix Array', 'Python', 'C++', 'Java', 'Python3', 'JavaScript']