The easiest possible solution (i think*) 😂UPVOTE IF IT HELPED MEANS A LOT TO ME TYYY 💜
Intuition\n Describe your first thoughts on how to solve this problem. \nLet\'s say we have an array that has n2+1 numbers in it. For anyone that actually knows
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nLet\'s say we have an array that has n*2+1 numbers in it. For anyone that actually knows basic maths this would be a dead giveaway that an array with that size cannot be divided into 2 seperate arrays such that their sizes are equal. So we return "false" for all the arrays that fit this if statement: if(nums.size() %2 == 1). After we get rid of all the arrays that have an odd size we move on to the real problem. We also have to make sure each array only consists of distinct/ unique numbers so that means that in the initial nums array there can\'t be more than 2 of the same number. We also need to make sure our for loop doesn\'t go ut of bounds so initialize i to 1. and finally we check if the number before and the number after our i are the same number as out nums[i]. If so we can return true, because that means in at least 1 of the 2 arrays we will have 2 of the same number. And if i gets to the end of the array without returning false, we return true since that means we can form 2 seperate arrays with distinct numbers and equal sizes. \n# Approach\n<!-- Describe your approach to solving the problem. -->\nLet\'s say we have an array that has n*2+1 numbers in it. For anyone that actually knows basic maths this would be a dead giveaway that an array with that size cannot be divided into 2 seperate arrays such that their sizes are equal. So we return "false" for all the arrays that fit this if statement: if(nums.size() %2 == 1). After we get rid of all the arrays that have an odd size we move on to the real problem. We also have to make sure each array only consists of distinct/ unique numbers so that means that in the initial nums array there can\'t be more than 2 of the same number. We also need to make sure our for loop doesn\'t go ut of bounds so initialize i to 1. and finally we check if the number before and the number after our i are the same number as out nums[i]. If so we can return true, because that means in at least 1 of the 2 arrays we will have 2 of the same number. And if i gets to the end of the array without returning false, we return true since that means we can form 2 seperate arrays with distinct numbers and equal sizes. \n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(n log n)\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(log n)\n# Code\n```\nclass Solution {\npublic:\n    bool isPossibleToSplit(vector<int>& nums) {\n        sort(nums.begin(), nums.end()); // sorts the vector to make it a lot easier for us :/\n        if(nums.size() %2 == 1) return false; // if the size is odd return false\n        for(int i = 1; i < nums.size()-1; i++) if(nums[i] == nums[i-1] && nums[i] == nums[i+1]) return false; // if the previus and the next number are the same as the ith number we return false since that prvents us from making 2 arrays with only distinct numbers\n        return true;\n    }\n};\n```
['C++']