question_slug stringlengths 3 77 | title stringlengths 1 183 | slug stringlengths 12 45 | summary stringlengths 1 160 ⌀ | author stringlengths 2 30 | certification stringclasses 2
values | created_at stringdate 2013-10-25 17:32:12 2025-04-12 09:38:24 | updated_at stringdate 2013-10-25 17:32:12 2025-04-12 09:38:24 | hit_count int64 0 10.6M | has_video bool 2
classes | content stringlengths 4 576k | upvotes int64 0 11.5k | downvotes int64 0 358 | tags stringlengths 2 193 | comments int64 0 2.56k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
split-the-array | Scala one-liner | scala-one-liner-by-hariprasath1436-z4fa | Explanation\n- nums.groupBy(identity): This groups the elements of the array nums based on their identity, effectively creating a map where the keys are the dis | hariprasath1436 | NORMAL | 2024-02-25T06:13:18.617881+00:00 | 2024-02-25T06:13:18.617911+00:00 | 23 | false | # Explanation\n- nums.groupBy(identity): This groups the elements of the array nums based on their identity, effectively creating a map where the keys are the distinct elements of nums and the values are arrays containing occurrences of those elements.\n\n- .mapValues(_.length): For each group (value) in the map, this ... | 2 | 0 | ['Scala'] | 0 |
split-the-array | Easiest Simple 5 -- different ways C // C++ // Python3 // Java // Python Beats 100% | easiest-simple-5-different-ways-c-c-pyth-9960 | Intuition\n\n\n\nC++ []\nclass Solution {\npublic:\n bool isPossibleToSplit(vector<int>& nums) {\n unordered_map<int, int> mp;\n for (auto& x : | Edwards310 | NORMAL | 2024-02-25T05:04:22.003168+00:00 | 2024-02-25T05:04:22.003199+00:00 | 58 | false | # Intuition\n\n\n![Screenshot 2024-02-25 095357.... | 2 | 0 | ['Array', 'Hash Table', 'C', 'Python', 'C++', 'Java', 'Python3'] | 0 |
split-the-array | Java Weekly Challenge | java-weekly-challenge-by-shree_govind_je-welq | 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 | Shree_Govind_Jee | NORMAL | 2024-02-25T04:55:23.025466+00:00 | 2024-02-25T04:55:23.025485+00:00 | 55 | false | # 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 {\n public boolean isPossibleToSplit(int[] nums) {\n Map<Integer, Integer> map = new HashMap<>()... | 2 | 0 | ['Hash Table', 'Hash Function', 'Java'] | 0 |
split-the-array | Using Hash Map | Simple and Easy | Python | using-hash-map-simple-and-easy-python-by-s7gm | Complexity\n- Time complexity: O(n)\n\n- Space complexity: O(n)\n\n# Code\n\nclass Solution:\n def isPossibleToSplit(self, nums: List[int]) -> bool:\n | pragya_2305 | NORMAL | 2024-02-25T04:19:21.464641+00:00 | 2024-02-25T04:19:21.464664+00:00 | 136 | false | # Complexity\n- Time complexity: O(n)\n\n- Space complexity: O(n)\n\n# Code\n```\nclass Solution:\n def isPossibleToSplit(self, nums: List[int]) -> bool:\n count = Counter(nums)\n \n for val in count.values():\n if val>2:\n return False\n return True\n``` | 2 | 0 | ['Hash Table', 'Python', 'Python3'] | 1 |
split-the-array | Full Intution From Scratch(You Won't Regret) C++ | full-intution-from-scratchyou-wont-regre-5ciw | Intuition\n###### <- As given in the question that nums is an array of even length,you have to split it into two parts such that they are equal in terms of leng | unvisitedNode_01 | NORMAL | 2024-02-25T04:04:33.490389+00:00 | 2024-02-27T08:27:54.916249+00:00 | 180 | false | # Intuition\n###### <- As given in the question that nums is an array of even length,you have to split it into two parts such that they are equal in terms of length and each part length will be (original length of array/2) (ofcourse becuase original array length is even so we can split it into two equal parts of same l... | 2 | 0 | ['Hash Table', 'C++'] | 0 |
split-the-array | ☑️✅Easy JAVA Solution || Beats 100%✅☑️ | easy-java-solution-beats-100-by-vritant-2dk1w | 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 | vritant-goyal | NORMAL | 2024-02-25T04:03:52.499276+00:00 | 2024-02-25T04:03:52.499313+00:00 | 121 | false | # 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 {\n public boolean isPossibleToSplit(int[] nums) {\n int n=nums.length;\n HashMap<Integer... | 2 | 0 | ['Java'] | 1 |
split-the-array | Pigeon Hole Principle | pigeon-hole-principle-by-kevinujunior-zo4w | Intuition\n Suppose we have m pigeons and n holes where m>n and we want to put m pigeons into n holes, then atleast one hole will have more than one pigeon. \n | kevinujunior | NORMAL | 2024-02-25T04:03:02.937360+00:00 | 2024-02-25T04:09:30.964556+00:00 | 101 | false | # Intuition\n* Suppose we have m pigeons and n holes where m>n and we want to put m pigeons into n holes, then atleast one hole will have more than one pigeon. \n* Similarly, if we have a number with frequency > 2 and we want to put this number into one of the 2 arrays then atleast one array will have the duplicate num... | 2 | 0 | ['C++'] | 0 |
split-the-array | Java Solution Map | java-solution-map-by-devanshi_bilthare-dkzk | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | Devanshi_Bilthare | NORMAL | 2024-02-25T04:03:02.727345+00:00 | 2024-02-25T04:03:02.727367+00:00 | 50 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\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. $$... | 2 | 0 | ['Java'] | 0 |
split-the-array | C++ 100% Fast | Easy Step By Step Explanation | c-100-fast-easy-step-by-step-explanation-3r0y | 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 | VYOM_GOYAL | NORMAL | 2024-02-25T04:02:39.449973+00:00 | 2024-02-25T04:02:39.449995+00:00 | 169 | false | # 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 mos... | 2 | 0 | ['Array', 'Ordered Map', 'C++'] | 0 |
split-the-array | ☑️ Splitting the Array. ☑️ | splitting-the-array-by-abdusalom_16-jrb0 | Code | Abdusalom_16 | NORMAL | 2025-04-06T12:05:37.378664+00:00 | 2025-04-06T12:05:37.378664+00:00 | 15 | false | # Code
```dart []
class Solution {
bool isPossibleToSplit(List<int> nums) {
nums.sort((a, b) => a.compareTo(b));
List<int> list1 = [];
List<int> list2 = [];
for(int i = 0; i < nums.length; i++){
if(!list1.contains(nums[i]) && list1.length <= list2.length){
list1.add(nums[i]);
... | 1 | 0 | ['Array', 'Hash Table', 'Counting', 'Dart'] | 0 |
split-the-array | Using HashMap = easy | using-hashmap-easy-by-sairangineeni-c252 | IntuitionStep 1: Count the frequency of each number in nums using a HashMap.
Step 2: Check if any number appears more than twice. If yes, return false.
Step 3: | Sairangineeni | NORMAL | 2025-02-28T08:13:30.542979+00:00 | 2025-02-28T08:13:30.542979+00:00 | 143 | false | # Intuition
Step 1: Count the frequency of each number in nums using a HashMap.
Step 2: Check if any number appears more than twice. If yes, return false.
Step 3: If the number of unique elements is at least nums.length / 2, return true; otherwise, return false.
# Code
```java []
class Solution {
public static boo... | 1 | 0 | ['Java'] | 0 |
split-the-array | Easy C++ aproach - frequency | easy-c-aproach-frequency-by-ju5t1natcodi-nofj | IntuitionWe can only have distinct numbers if their frequency is at most 2, because if it is at least 3, than at least one of the arrays will have at least 2 eq | Ju5t1natcoding | NORMAL | 2025-02-19T19:54:50.628685+00:00 | 2025-02-19T19:54:50.628685+00:00 | 52 | false | # Intuition
We can only have distinct numbers if their frequency is at most 2, because if it is at least 3, than at least one of the arrays will have at least 2 equal elements. Therefore, we count the numbers frequency and constantly check if their frequency is at least 3 or not.
# Approach
Create an array in which we... | 1 | 0 | ['C++'] | 0 |
split-the-array | Counter is the !!KEY!! Beats 100% + Beginner Friendly :) | counter-is-the-key-beats-100-beginner-fr-7kbm | IntuitionThe problem requires us to split the given array into two parts such that both contain distinct elements. The key observation is that if any number app | lil77 | NORMAL | 2025-02-17T07:49:36.668226+00:00 | 2025-02-17T07:49:36.668226+00:00 | 84 | false | 
# Intuition
The problem requires us to split the given array into two parts such that both contain distinct elements. The key observation is that if any number appears more than twice, it becomes impossib... | 1 | 0 | ['Python3'] | 0 |
split-the-array | Solution in Java and C | solution-in-java-and-c-by-vickyy234-g8tx | Code | vickyy234 | NORMAL | 2025-02-12T04:46:51.886298+00:00 | 2025-02-12T04:46:51.886298+00:00 | 127 | false | # Code
```java []
class Solution {
public boolean isPossibleToSplit(int[] nums) {
int len = nums.length;
int[] freq = new int[101];
for (int i = 0; i < len; i++) {
freq[nums[i]]++;
if (freq[nums[i]] > 2) {
return false;
}
}
... | 1 | 0 | ['Array', 'C', 'Counting', 'Java'] | 0 |
split-the-array | Easiest Solution in Java | easiest-solution-in-java-by-sathurnithy-cuom | Code | Sathurnithy | NORMAL | 2025-02-11T05:49:57.999149+00:00 | 2025-02-11T05:49:57.999149+00:00 | 126 | false | # Code
```java []
class Solution {
public boolean isPossibleToSplit(int[] nums) {
int[] freq = new int[101];
for (int value : nums) {
if (freq[value]++ >= 2)
return false;
}
return true;
}
}
``` | 1 | 0 | ['Array', 'Counting', 'Java'] | 0 |
split-the-array | Easiest Solution in C | easiest-solution-in-c-by-sathurnithy-xbdp | Code | Sathurnithy | NORMAL | 2025-02-11T05:45:55.812306+00:00 | 2025-02-11T05:45:55.812306+00:00 | 26 | false | # Code
```c []
bool isPossibleToSplit(int* nums, int numsSize) {
int freq[101] = {0};
for (int i = 0; i < numsSize; i++) {
freq[nums[i]]++;
if (freq[nums[i]] > 2)
return false;
}
return true;
}
``` | 1 | 0 | ['Array', 'C', 'Counting'] | 0 |
split-the-array | C++ Simple and Short, Using Hashmap, 0 ms Beats 100% | c-simple-and-short-using-hashmap-0-ms-be-69s0 | Code\ncpp []\nclass Solution {\npublic:\n bool isPossibleToSplit(vector<int>& nums) {\n unordered_map<int, int> freq;\n for (auto n : nums) {\n | yehudisk | NORMAL | 2024-11-25T13:26:46.431744+00:00 | 2024-11-25T13:26:46.431782+00:00 | 73 | false | # Code\n```cpp []\nclass Solution {\npublic:\n bool isPossibleToSplit(vector<int>& nums) {\n unordered_map<int, int> freq;\n for (auto n : nums) {\n if (freq[n] == 2) return false;\n freq[n]++;\n }\n return true;\n }\n};\n``` | 1 | 0 | ['C++'] | 0 |
split-the-array | Easy to understand | easy-to-understand-by-abhinav_bal-9nct | \n\n# Code\npython []\nclass Solution(object):\n def isPossibleToSplit(self, nums):\n """\n :type nums: List[int]\n :rtype: bool\n | Abhinav_Bal | NORMAL | 2024-11-16T16:24:31.672871+00:00 | 2024-11-16T16:24:31.672909+00:00 | 17 | false | \n\n# Code\n```python []\nclass Solution(object):\n def isPossibleToSplit(self, nums):\n """\n :type nums: List[int]\n :rtype: bool\n """\n unique_elements = len(set(nums))\n n = len(nums)\n if unique_elements < n // 2:\n return False\n \n for i i... | 1 | 0 | ['Python'] | 0 |
split-the-array | Solution using hashmap 100% beat | solution-using-hashmap-100-beat-by-cs_22-469h | \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# | CS_2201640100153 | NORMAL | 2024-11-07T05:44:49.961614+00:00 | 2024-11-07T05:44:49.961653+00:00 | 27 | false | \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```python3 []\nclass Solution:\n def isPossibleToSplit(self, nums: List[int]) -> bool:\n if len(nums)%2!=0:\n r... | 1 | 0 | ['Array', 'Hash Table', 'Counting', 'Python3'] | 0 |
split-the-array | Friendly & Clear | friendly-clear-by-anevil-3555 | Complexity\n- Time complexity: O(N)\n\n- Space complexity: O(N)\n Add your space complexity here, e.g. O(n) \n\n# Code\ncsharp []\npublic class Solution {\n | Anevil | NORMAL | 2024-10-09T12:45:53.108020+00:00 | 2024-10-09T12:45:53.108051+00:00 | 15 | false | # Complexity\n- Time complexity: O(N)\n\n- Space complexity: O(N)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```csharp []\npublic class Solution {\n public bool IsPossibleToSplit(int[] nums) \n {\n var nums1 = new HashSet<int>();\n var nums2 = new HashSet<int>();\n\n f... | 1 | 0 | ['C#'] | 0 |
split-the-array | Check If Splitting is Possible with Frequency Constraint Using C++ | check-if-splitting-is-possible-with-freq-3vef | Intuition\nThe first step to determine if the array can be split is to ensure that no element appears more than twice, as this would violate the conditions for | Krishnaa2004 | NORMAL | 2024-09-07T17:56:34.221639+00:00 | 2024-09-07T17:56:34.221659+00:00 | 244 | false | # Intuition\nThe first step to determine if the array can be split is to ensure that no element appears more than twice, as this would violate the conditions for a valid split.\n\n# Approach\n- Traverse the array and use an unordered map to count the frequency of each element.\n- If any element appears more than twice,... | 1 | 0 | ['C++'] | 0 |
split-the-array | Easy Solution || Beginner Friendly✔✔✔ || Easy Concept ☠☠☠ | easy-solution-beginner-friendly-easy-con-xs57 | Complexity\n- Time complexity: O(NLogN)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(1)\n Add your space complexity here, e.g. O(n) \n\n | ahnnikmisra | NORMAL | 2024-07-24T16:42:19.560501+00:00 | 2024-07-24T16:42:19.560526+00:00 | 17 | false | # Complexity\n- Time complexity: O(NLogN)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n public boolean isPossibleToSplit(int[] nums) {\n java.util.Arrays.sort(nums);\n int cur... | 1 | 0 | ['Java'] | 0 |
split-the-array | Using Map Easy Approach | using-map-easy-approach-by-shikhar_4s-w4wk | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | Shikhar_4s | NORMAL | 2024-07-20T20:48:47.023745+00:00 | 2024-07-20T20:48:47.023762+00:00 | 158 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 1 | 0 | ['C++'] | 1 |
split-the-array | Simple java solution | simple-java-solution-by-kramprakash2005-09we | Intuition\n Describe your first thoughts on how to solve this problem. \nThe intuition behind the solution provided is to sort the array nums. After sorting, if | kramprakash2005 | NORMAL | 2024-06-20T08:14:49.236868+00:00 | 2024-06-20T08:14:49.236904+00:00 | 8 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe intuition behind the solution provided is to sort the array nums. After sorting, if there exists any element in the sorted array such that it is equal to the element two positions ahead of it (nums[i] == nums[i+2]), then it\'s not pos... | 1 | 0 | ['Java'] | 0 |
split-the-array | Simple C Solution (frequency method) 100% | simple-c-solution-frequency-method-100-b-u5ho | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n1. find if any number a | rajnarayansharma110 | NORMAL | 2024-04-08T18:08:52.910425+00:00 | 2024-04-08T18:08:52.910458+00:00 | 22 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. find if any number appear more then twice\n# Complexity\n- Time complexity:O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(1)\n<... | 1 | 0 | ['C'] | 0 |
split-the-array | The easiest possible solution (i think*) 😂UPVOTE IF IT HELPED MEANS A LOT TO ME TYYY 💜 | the-easiest-possible-solution-i-think-up-25e0 | 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 | marzex | NORMAL | 2024-03-30T16:46:04.196655+00:00 | 2024-03-30T16:46:04.196678+00:00 | 80 | false | # 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 w... | 1 | 0 | ['C++'] | 1 |
split-the-array | simple and using dictionary 89.22 % Time and 95.66 % Space | simple-and-using-dictionary-8922-time-an-mlwc | Intuition\nThe intuition behind solving this problem is to iterate through the given list of integers and keep track of the count of occurrences of each element | Umarulshahin | NORMAL | 2024-03-28T10:54:59.980974+00:00 | 2024-03-28T10:54:59.980991+00:00 | 38 | false | # Intuition\nThe intuition behind solving this problem is to iterate through the given list of integers and keep track of the count of occurrences of each element. If any element appears more than twice, it indicates that it is not possible to split the list into two parts such that each part contains the same number o... | 1 | 0 | ['Python3'] | 1 |
split-the-array | Easy to understand || 100% Faster || Ruby | easy-to-understand-100-faster-ruby-by-ya-xlqg | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | yashwardhan24_sharma | NORMAL | 2024-03-19T09:51:18.489022+00:00 | 2024-03-19T09:51:18.489054+00:00 | 90 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 1 | 0 | ['Ruby'] | 0 |
split-the-array | Easy Solution with Hash Table || C++ || Java || Python | easy-solution-with-hash-table-c-java-pyt-16sv | Intuition\n Describe your first thoughts on how to solve this problem. \nCount the frequency of the element in the array! if any element exist more then twice r | mahfuz2411 | NORMAL | 2024-03-11T11:38:11.299804+00:00 | 2024-03-11T11:38:11.299839+00:00 | 69 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nCount the frequency of the element in the array! if any element exist more then twice return false! Otherwise return true;\n\n# Approach\nCounting, Hash Table\n\n# Complexity\n- Time complexity: O(n)\n\n- Space complexity: O(n)\n\n# Codes... | 1 | 0 | ['Array', 'Hash Table', 'Counting', 'Python', 'C++', 'Java'] | 0 |
split-the-array | SOLUTION | solution-by-kodiac1-j1s5 | Intuition\nthis solution is based on counting the frequencies of elements inside the array\n\n# Approach\nthe solution comprises of 3 cases \ntake two variables | Kodiac1 | NORMAL | 2024-03-06T07:48:21.917171+00:00 | 2024-03-06T07:48:21.917203+00:00 | 72 | false | # Intuition\nthis solution is based on counting the frequencies of elements inside the array\n\n# Approach\nthe solution comprises of 3 cases \ntake two variables size1 and size2 and initialise them to 0\n**case 1**-> if the frequency of any element is greater than 2 ,then that element will defenitly repeat in the othe... | 1 | 0 | ['Hash Table', 'Counting', 'C++'] | 0 |
split-the-array | Simple Beginner friendly C++ Code | Beats 90 % users | simple-beginner-friendly-c-code-beats-90-fm34 | Intuition\n Describe your first thoughts on how to solve this problem. \nif a number occurs 2 times we can insert each in 2 array but if it occurs more than 2 t | srajyavardhan12 | NORMAL | 2024-03-01T02:07:40.840117+00:00 | 2024-03-01T02:07:40.840149+00:00 | 5 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nif a number occurs 2 times we can insert each in 2 array but if it occurs more than 2 times than atleast one of the splited array will have duplicate value, so we will simple count freq of each element\n\n# Approach\n<!-- Describe your ap... | 1 | 0 | ['C++'] | 0 |
split-the-array | Ruby one-liner | ruby-one-liner-by-dnnx-kc1r | \ndef is_possible_to_split(nums) = nums.tally.values.max <= 2 \n | dnnx | NORMAL | 2024-02-29T21:52:22.133015+00:00 | 2024-02-29T21:52:22.133042+00:00 | 8 | false | ```\ndef is_possible_to_split(nums) = nums.tally.values.max <= 2 \n``` | 1 | 0 | ['Ruby'] | 0 |
split-the-array | Ruby 1-line Simple Solution | ruby-1-line-simple-solution-by-vladhilko-fubh | Code\n\n# @param {Integer[]} nums\n# @return {Boolean}\ndef is_possible_to_split(nums)\n nums.tally.all? { _2 <= 2 }\nend\n | vladhilko | NORMAL | 2024-02-29T15:06:43.186474+00:00 | 2024-02-29T15:06:43.186555+00:00 | 9 | false | # Code\n```\n# @param {Integer[]} nums\n# @return {Boolean}\ndef is_possible_to_split(nums)\n nums.tally.all? { _2 <= 2 }\nend\n``` | 1 | 0 | ['Ruby'] | 1 |
split-the-array | Easy-Peasy C++ Solution 🙌🙌 | easy-peasy-c-solution-by-jasneet_aroraaa-hjgg | Code\n\nclass Solution {\npublic:\n bool isPossibleToSplit(vector<int>& nums) {\n unordered_map<int, int> hash;\n for (int i = 0; i < nums.size | jasneet_aroraaa | NORMAL | 2024-02-25T13:21:30.901859+00:00 | 2024-02-25T13:22:35.382702+00:00 | 51 | false | # Code\n```\nclass Solution {\npublic:\n bool isPossibleToSplit(vector<int>& nums) {\n unordered_map<int, int> hash;\n for (int i = 0; i < nums.size(); i++) {\n hash[nums[i]]++;\n if (hash[nums[i]] > 2) return false;\n }\n return true;\n }\n};\n``` | 1 | 0 | ['Math', 'Counting', 'Iterator', 'Hash Function', 'C++'] | 0 |
split-the-array | 1-line Linq | 1-line-linq-by-3s_akb-36wa | \n# Code\n\npublic class Solution {\n public bool IsPossibleToSplit(int[] nums) {\n return nums.GroupBy(x => x).All(x => x.Count() <= 2);\n }\n}\n | 3S_AKB | NORMAL | 2024-02-25T10:51:43.273341+00:00 | 2024-02-25T10:51:43.273366+00:00 | 37 | false | \n# Code\n```\npublic class Solution {\n public bool IsPossibleToSplit(int[] nums) {\n return nums.GroupBy(x => x).All(x => x.Count() <= 2);\n }\n}\n``` | 1 | 0 | ['C#'] | 0 |
split-the-array | Easy To Understand C++ Solution || (Using Map)✅✅ | easy-to-understand-c-solution-using-map-3bqon | Code\n\nclass Solution {\npublic:\n bool isPossibleToSplit(vector<int>& nums) {\n int n=nums.size();\n unordered_map<int,int> mp;\n if(n | Abhi242 | NORMAL | 2024-02-25T07:07:39.406283+00:00 | 2024-02-25T07:07:39.406312+00:00 | 93 | false | # Code\n```\nclass Solution {\npublic:\n bool isPossibleToSplit(vector<int>& nums) {\n int n=nums.size();\n unordered_map<int,int> mp;\n if(n%2!=0){\n return false;\n }\n for(int i=0;i<n;i++){\n mp[nums[i]]++;\n }\n for(auto a: mp){\n ... | 1 | 0 | ['Hash Table', 'C++'] | 0 |
split-the-array | Easy Solution || Beats 100%🔥💥 | easy-solution-beats-100-by-eraofkaushik0-lb7r | \n\n\n# Code\n\nclass Solution:\n def isPossibleToSplit(self, nums: List[int]) -> bool:\n c = Counter(nums)\n for i in c:\n if c[i] | EraOfKaushik003 | NORMAL | 2024-02-25T06:43:25.887258+00:00 | 2024-02-25T06:43:25.887310+00:00 | 9 | false | \n\n\n# Code\n```\nclass Solution:\n def isPossibleToSplit(self, nums: List[int]) -> bool:\n c = Counter(nums)\n for i in c:\n if c[i] > 2:\n return False\n ... | 1 | 0 | ['Hash Table', 'Counting', 'Python3'] | 0 |
split-the-array | Simple C++ | simple-c-by-deva766825_gupta-pdz5 | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | deva766825_gupta | NORMAL | 2024-02-25T04:59:22.031774+00:00 | 2024-02-25T04:59:22.031797+00:00 | 4 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 1 | 0 | ['C++'] | 0 |
split-the-array | Day-4 | day-4-by-maahigarg-eyhy | IntuitionEach number in nums should appear at most twice total(Once for the first array,Once for the second array).If any number appears 3 times or more, it's i | MaahiGarg | NORMAL | 2025-04-10T18:05:12.700962+00:00 | 2025-04-10T18:05:12.700962+00:00 | 1 | false | # Intuition
Each number in nums should appear at most twice total(Once for the first array,Once for the second array).If any number appears 3 times or more, it's impossible to split without duplicates.
# Approach
Using hash map, we count the frequency of each element and if it is greater than 2 then return false else ... | 0 | 0 | ['C++'] | 0 |
split-the-array | ok | ok-by-akshay____p-m2v7 | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | Akshay____P | NORMAL | 2025-04-07T06:02:49.663296+00:00 | 2025-04-07T06:02:49.663296+00:00 | 1 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
`... | 0 | 0 | ['JavaScript'] | 0 |
split-the-array | 3046. Split the Array | Java | HashMap | 3046-split-the-array-java-hashmap-by-_aj-50m6 | Code | _Ajit_Singh_ | NORMAL | 2025-04-04T04:25:48.620190+00:00 | 2025-04-04T04:25:48.620190+00:00 | 1 | false | # Code
```java []
class Solution {
public boolean isPossibleToSplit(int[] nums) {
Map<Integer, Integer> map = new HashMap<>();
for (int num : nums)
map.put(num, map.getOrDefault(num, 0) + 1);
for (Map.Entry<Integer, Integer> entry : map.entrySet())
if (entry.getValu... | 0 | 0 | ['Hash Table', 'Counting', 'Java'] | 0 |
split-the-array | Java | Cakewalk Solution 🍰 | 100% Faster | java-cakewalk-solution-100-faster-by-tej-vl7h | IntuitionWe need to split the given array nums into two equal halves, nums1 and nums2, while ensuring that both contain distinct elements.To do this, no element | teja_1403 | NORMAL | 2025-04-01T05:05:03.665669+00:00 | 2025-04-01T05:05:03.665669+00:00 | 1 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
We need to split the given array nums into two equal halves, nums1 and nums2, while ensuring that both contain distinct elements.
To do this, no element in nums should appear more than twice. If any number appears more than twice, we canno... | 0 | 0 | ['Array', 'Math', 'Java'] | 0 |
split-the-array | TP | tp-by-sangram1989-a9go | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | Sangram1989 | NORMAL | 2025-03-31T18:36:35.718383+00:00 | 2025-03-31T18:36:35.718383+00:00 | 1 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
`... | 0 | 0 | ['Java'] | 0 |
split-the-array | Simple Swift Solution | simple-swift-solution-by-felisviridis-ympr | CodeCode | Felisviridis | NORMAL | 2025-03-31T08:33:56.857369+00:00 | 2025-03-31T08:38:12.534630+00:00 | 2 | false | 
# Code
```swift []
class Solution {
func isPossibleToSplit(_ nums: [Int]) -> Bool {
var freq = [Int: Int]()
for num in nums {
freq[num, defau... | 0 | 0 | ['Swift'] | 0 |
split-the-array | isPossibleToSplit c++ | ispossibletosplit-c-by-glider4d-evr9 | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | glider4d | NORMAL | 2025-03-24T22:52:23.205796+00:00 | 2025-03-24T22:52:23.205796+00:00 | 2 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
`... | 0 | 0 | ['C++'] | 0 |
split-the-array | EASY PYTHON CODE | easy-python-code-by-vishnuande2006-xr8z | Code | vishnuande2006 | NORMAL | 2025-03-24T15:44:14.049374+00:00 | 2025-03-24T15:44:14.049374+00:00 | 2 | false |
# Code
```python3 []
class Solution:
def isPossibleToSplit(self, nums: List[int]) -> bool:
nums.sort()
n1 = []
n2 = []
for i in range(0,len(nums),2):
n1.append(nums[i])
n2.append(nums[i+1])
if len(set(n1)) == len(set(n2)) == (len(nums)//2):
... | 0 | 0 | ['Python3'] | 0 |
split-the-array | split the array easy solution for beginner beats[45%] | split-the-array-easy-solution-for-beginn-c6ya | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | Abhishek-web | NORMAL | 2025-03-24T14:20:11.602007+00:00 | 2025-03-24T14:20:11.602007+00:00 | 2 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
`... | 0 | 0 | ['C++'] | 0 |
split-the-array | Easy Solution with frequency approach | easy-solution-with-frequency-approach-by-uo4o | IntuitionHere our intution is to make distinct numbers in each array the count in each array should not be >1 i.e count in original array should not be >2.Appr | Kartisan | NORMAL | 2025-03-20T09:31:25.075538+00:00 | 2025-03-20T09:31:25.075538+00:00 | 3 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
Here our intution is to make distinct numbers in each array the count in each array should not be >1 i.e count in original array should not be >2.
# Approach
<!-- Describe your approach to solving the problem. -->
Creating a Frequency arr... | 0 | 0 | ['Java'] | 0 |
split-the-array | easy | easy-by-mr_ramzan-ubnl | Code | mr_ramzan | NORMAL | 2025-03-17T17:14:22.777351+00:00 | 2025-03-17T17:14:22.777351+00:00 | 2 | false |
# Code
```cpp []
class Solution {
public:
bool isPossibleToSplit(vector<int>& nums) {
unordered_map<int,int> map;
for(int &n:nums) map[n]++;
for(auto &p:map){
if(p.second>2) return false;
}
return true;
}
};
``` | 0 | 0 | ['Array', 'Hash Table', 'Counting', 'C++'] | 0 |
split-the-array | Easy to understand solution in Java. Beats 93.14 % | easy-to-understand-solution-in-java-beat-t7o1 | Complexity
Time complexity:
O(n)
Space complexity:
O(n)
Code | Khamdam | NORMAL | 2025-03-14T15:57:59.566884+00:00 | 2025-03-14T15:57:59.566884+00:00 | 3 | false | # Complexity
- Time complexity:
O(n)
- Space complexity:
O(n)
# Code
```java []
class Solution {
public boolean isPossibleToSplit(int[] nums) {
int[] freq = new int[101];
for (int num : nums) {
freq[num]++;
if (freq[num] > 2) {
return false;
}
... | 0 | 0 | ['Java'] | 0 |
split-the-array | Solution which is done in 100 beats | solution-which-is-done-in-100-beats-by-p-4370 | IntuitionApproachComplexity
Time complexity:
O(n)
Space complexity:
O(n)
Code | Pedapudi_Akhila | NORMAL | 2025-03-13T10:44:51.149456+00:00 | 2025-03-13T10:44:51.149456+00:00 | 5 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
O(n)
- Space complexity:
O(n)
# Code
```cpp []
class Solution {
public:
bool isPossibleToSplit(vector<int>& nums)
{
int n... | 0 | 0 | ['C++'] | 0 |
split-the-array | Solution in java | solution-in-java-by-suraj_khatri11-9o61 | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | suraj_khatri11 | NORMAL | 2025-03-11T10:09:32.223194+00:00 | 2025-03-11T10:09:32.223194+00:00 | 2 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
`... | 0 | 0 | ['Java'] | 0 |
split-the-array | C++ beginners friendly solution | c-beginners-friendly-solution-by-neharaj-rcuz | IntuitionApproachfirst sort the array
just comparing the occurence of elemnts if it is 3 times than it should return falseComplexity
Time complexity:
Space com | NehaRajpoot | NORMAL | 2025-03-09T06:23:16.663128+00:00 | 2025-03-09T06:23:16.663128+00:00 | 4 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
first sort the array
just comparing the occurence of elemnts if it is 3 times than it should return false
# Complexity
- Time complexity:
<!-- Add your time complexity her... | 0 | 0 | ['C++'] | 0 |
split-the-array | best approach | best-approach-by-prince_singh_008-y1t8 | IntuitionApproachComplexity
Time complexity:
o(n)
Space complexity:
Code | prince_singh_007_ | NORMAL | 2025-03-05T19:31:36.636204+00:00 | 2025-03-05T19:31:36.636204+00:00 | 4 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
o(n)
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# C... | 0 | 0 | ['C++'] | 0 |
split-the-array | Using Hash map | using-hash-map-by-ritam05-yuwa | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | Ritam_Majumdar | NORMAL | 2025-03-04T07:52:03.951963+00:00 | 2025-03-04T07:52:03.951963+00:00 | 2 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
`... | 0 | 0 | ['C++'] | 0 |
split-the-array | 🐍fastest solution💥🔥✅ | fastest-solution-by-juantorrenegra-7bhr | Intuitionif a number is repeated more than 2 times return FalseApproachdo a for loop checking if any nums.count is higher than 2Complexity
Time complexity:
O(n | juantorrenegra | NORMAL | 2025-02-27T17:55:30.933312+00:00 | 2025-02-27T17:55:30.933312+00:00 | 3 | false | # Intuition
if a number is repeated more than 2 times return False
# Approach
do a for loop checking if any nums.count is higher than 2
# Complexity
- Time complexity:
O(n2)
- Space complexity:
O(1)
# Code
```python []
class Solution(object):
def isPossibleToSplit(self, nums):
for i in nums:
... | 0 | 0 | ['Python'] | 0 |
split-the-array | Pyhton 3 - Beats 100% | pyhton-3-beats-100-by-zacharylupstein-ni4t | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | zacharylupstein | NORMAL | 2025-02-27T02:23:26.471394+00:00 | 2025-02-27T02:23:26.471394+00:00 | 2 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
`... | 0 | 0 | ['Python3'] | 0 |
split-the-array | hash map | hash-map-by-qahramon1111-igh4 | Intuitionso instead of sitting down and thinking about how do i solve this problem i used the hashmap data sructure.ApproachEasy approach is that u get the elem | jamesromanov | NORMAL | 2025-02-24T13:10:43.178062+00:00 | 2025-02-24T13:10:43.178062+00:00 | 2 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
so instead of sitting down and thinking about how do i solve this problem i used the hashmap data sructure.
# Approach
<!-- Describe your approach to solving the problem. -->
Easy approach is that u get the elements and occurences of them a... | 0 | 0 | ['JavaScript'] | 0 |
split-the-array | Python (Simple Hashmap) | python-simple-hashmap-by-nk_nidhi-sae6 | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | NK_nidhi | NORMAL | 2025-02-21T15:20:42.676230+00:00 | 2025-02-21T15:20:42.676230+00:00 | 2 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
`... | 0 | 0 | ['Python3'] | 0 |
split-the-array | Easy Solution 🚀 || C++ || Beats 100% || TC - O(n) | easy-solution-c-beats-100-tc-on-by-nitin-nkhw | Complexity
Time complexity: O(n)
Space complexity: O(n)
Code | nitinkumar-19 | NORMAL | 2025-02-20T17:08:19.489771+00:00 | 2025-02-20T17:08:19.489771+00:00 | 4 | false | # Complexity
- Time complexity: O(n)
- Space complexity: O(n)
# Code
```cpp []
class Solution {
public:
bool isPossibleToSplit(vector<int>& nums) {
unordered_map<int, int> mp;
for(int i=0;i<nums.size();i++){
mp[nums[i]]++;
if(mp[nums[i]]>2) return false;
}
... | 0 | 0 | ['C++'] | 0 |
split-the-array | Optimized simple solution - beats 93.51%🔥 | optimized-simple-solution-beats-9351-by-pioqx | Complexity
Time complexity: O(N)
Space complexity: O(1)
Code | cyrusjetson | NORMAL | 2025-02-17T07:02:54.956804+00:00 | 2025-02-17T07:02:54.956804+00:00 | 4 | false | # Complexity
- Time complexity: O(N)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity: O(1)
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
```java []
class Solution {
public boolean isPossibleToSplit(int[] nums) {
int[] t = new int[101];
for (int i :... | 0 | 0 | ['Java'] | 0 |
split-the-array | SPLIT THE ARRAY. | split-the-array-by-itz_shrivastava_ji-bn7t | IntuitionAS IT WWAS CLEAR FROM THE QUESTION THAT ELEMENTS SHOULD BE DISTINCT , SO THE COUNT OF THE ELEMENT CANT EXCEED 2 RIGHT , AND THE LENGTH OF THE ARRAY SHO | itz_Shrivastava_Ji | NORMAL | 2025-02-14T04:07:20.889691+00:00 | 2025-02-14T04:07:20.889691+00:00 | 4 | false | # Intuition
AS IT WWAS CLEAR FROM THE QUESTION THAT ELEMENTS SHOULD BE DISTINCT , SO THE COUNT OF THE ELEMENT CANT EXCEED 2 RIGHT , AND THE LENGTH OF THE ARRAY SHOULD BE EVEN ALSO .
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
#... | 0 | 0 | ['Array', 'Hash Table', 'C++'] | 0 |
split-the-array | if(looking for easy solution){1ms , 99% beats solution is here for you}else{continue;} | iflooking-for-easy-solution1ms-99-beats-gstzn | follow me on instagram : @ku_.k_kuApproachComplexity
Time complexity:
Space complexity:
Code | mernstack | NORMAL | 2025-02-12T13:16:27.419900+00:00 | 2025-02-12T13:16:27.419900+00:00 | 1 | false | follow me on instagram : @ku_.k_ku
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
```javascript []
/**
* @param {number[]} nums
... | 0 | 0 | ['JavaScript'] | 0 |
split-the-array | Easy solution | easy-solution-by-gandhip1361-vxcy | IntuitionApproachComplexity
Time complexity:
O(n)
Space complexity:
O(n)
Code | gandhip1361 | NORMAL | 2025-02-11T13:52:14.449750+00:00 | 2025-02-11T13:52:14.449750+00:00 | 3 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
O(n)
- Space complexity:
O(n)
# Code
```java []
class Solution {
public boolean isPossibleToSplit(int[] nums) {
if (nums.leng... | 0 | 0 | ['Hash Table', 'Java'] | 0 |
number-complement | 3-line / 1-line C++ | 3-line-1-line-c-by-lzl124631x-7n5q | See my latest update in repo LeetCode\n\n## Solution 1.\n\n\n// OJ: https://leetcode.com/problems/number-complement/\n// Author: github.com/lzl124631x\n// Time: | lzl124631x | NORMAL | 2017-01-08T09:13:16.218000+00:00 | 2022-01-04T08:00:08.950121+00:00 | 56,275 | false | See my latest update in repo [LeetCode](https://github.com/lzl124631x/LeetCode)\n\n## Solution 1.\n\n```\n// OJ: https://leetcode.com/problems/number-complement/\n// Author: github.com/lzl124631x\n// Time: O(1) as there are at most 32 bits to move\n// Space: O(1)\nclass Solution {\npublic:\n int findComplement(int n... | 290 | 3 | [] | 46 |
number-complement | Java, very simple code and self-evident, explanation | java-very-simple-code-and-self-evident-e-0gba | for example:\n100110, its complement is 011001, the sum is 111111. So we only need get the min number large or equal to num, then do substraction\n\n public | dongdl | NORMAL | 2017-01-16T06:07:42.142000+00:00 | 2018-10-01T21:27:07.933367+00:00 | 32,526 | false | for example:\n100110, its complement is 011001, the sum is 111111. So we only need get the min number large or equal to num, then do substraction\n```\n public int findComplement(int num) \n {\n int i = 0;\n int j = 0;\n \n while (i < num)\n {\n i += Math.pow(2, j);\n... | 238 | 1 | [] | 30 |
number-complement | ✅100.0%🔥Easy Solution🔥With Explanation🔥 | 1000easy-solutionwith-explanation-by-mra-i4uk | Intuition\n#### When asked to find the complement of an integer, the idea is to flip every bit in its binary representation\u2014changing 0s to 1s and 1s to 0s. | MrAke | NORMAL | 2024-08-22T01:10:06.304091+00:00 | 2024-08-22T01:10:06.304113+00:00 | 42,710 | false | # Intuition\n#### When asked to find the complement of an integer, the idea is to flip every bit in its binary representation\u2014changing `0`s to `1`s and `1`s to `0`s. For example, the complement of 5 (which is `101` in binary) is `010`, which is `2` in decimal.\n---\n\n# Approach\n#### `Determine the Binary Length`... | 185 | 2 | ['Bit Manipulation', 'Python', 'C++', 'Java', 'Python3', 'JavaScript', 'C#'] | 17 |
number-complement | Simple Python | simple-python-by-ipeq1-hcy8 | \nclass Solution(object):\n def findComplement(self, num):\n i = 1\n while i <= num:\n i = i << 1\n return (i - 1) ^ num\n\n\ | ipeq1 | NORMAL | 2017-01-08T07:30:34.390000+00:00 | 2022-07-11T20:09:43.942562+00:00 | 27,972 | false | ```\nclass Solution(object):\n def findComplement(self, num):\n i = 1\n while i <= num:\n i = i << 1\n return (i - 1) ^ num\n```\n\nFYI: pomodoro timer helps to obtain higher time ROI: [e-tomato.online](http://e-tomato.online) | 152 | 1 | [] | 27 |
number-complement | Java 1 line bit manipulation solution | java-1-line-bit-manipulation-solution-by-b7vs | I post solution first and then give out explanation. Please think why does it work before read my explanation.\n\n\npublic class Solution {\n public int find | shawngao | NORMAL | 2017-01-08T13:52:23.355000+00:00 | 2018-10-03T13:32:39.294822+00:00 | 52,527 | false | I post solution first and then give out explanation. Please think why does it work before read my explanation.\n\n```\npublic class Solution {\n public int findComplement(int num) {\n return ~num & ((Integer.highestOneBit(num) << 1) - 1);\n }\n}\n```\n\nAccording to the problem, the result is\n1. The ```fl... | 135 | 0 | [] | 31 |
number-complement | C++ EASY TO SOLVE || Different Variations of code with detailed exaplanations | c-easy-to-solve-different-variations-of-af9vu | Given a positive integer, output its complement number. The complement strategy is to flip the bits of its binary representation.\n\nIntuition:-\nThere is not m | Cosmic_Phantom | NORMAL | 2021-12-27T03:15:41.395534+00:00 | 2024-08-23T02:30:11.539435+00:00 | 11,162 | false | Given a positive integer, output its complement number. The complement strategy is to flip the bits of its binary representation.\n\n**Intuition:-**\nThere is not much of a intuition in this question as the question is loud and clear about it\'s use of bit manipulation .\n\nTo make things a bit more interesting let\'s ... | 122 | 14 | ['Bit Manipulation', 'C', 'C++'] | 9 |
number-complement | maybe fewest operations | maybe-fewest-operations-by-stefanpochman-dsaj | Spread the highest 1-bit onto all the lower bits. Then xor with that.\n\nint findComplement(int num) {\n int mask = num;\n mask |= mask >> 1;\n mask |= | stefanpochmann | NORMAL | 2017-01-10T16:15:52.171000+00:00 | 2018-10-19T13:13:24.644131+00:00 | 16,282 | false | Spread the highest 1-bit onto all the lower bits. Then xor with that.\n```\nint findComplement(int num) {\n int mask = num;\n mask |= mask >> 1;\n mask |= mask >> 2;\n mask |= mask >> 4;\n mask |= mask >> 8;\n mask |= mask >> 16;\n return num ^ mask;\n}\n``` | 110 | 3 | [] | 12 |
number-complement | Python 4 ways | python-4-ways-by-flag_to-lg8h | Flip bit by bit.\n\nclass Solution(object):\n def findComplement(self, num):\n i = 1\n while num >= i:\n num ^= i\n i <<= | flag_to | NORMAL | 2017-01-10T21:35:42.028000+00:00 | 2018-09-21T16:04:22.966292+00:00 | 7,621 | false | 1. Flip bit by bit.\n```\nclass Solution(object):\n def findComplement(self, num):\n i = 1\n while num >= i:\n num ^= i\n i <<= 1\n return num\n```\n2. Find the bit length (say L) and flip num by **num ^ 11...1** (L ones).\n```\n def findComplement(self, num):\n ... | 65 | 1 | [] | 9 |
number-complement | ✅ [C++/Python] Simple Solutions w/ Explanation | Brute-Force +Bit-Manipulation Tricks + In-Built | cpython-simple-solutions-w-explanation-b-t3vb | We are given an integer num and we need to return its complement\n\n---\n\n\u2714\uFE0F Solution - I (Brute-Force)\n\nWe can simply iterate and find the leftmos | archit91 | NORMAL | 2021-12-27T07:47:23.888883+00:00 | 2021-12-27T09:04:20.143868+00:00 | 3,411 | false | We are given an integer `num` and we need to return its complement\n\n---\n\n\u2714\uFE0F ***Solution - I (Brute-Force)***\n\nWe can simply iterate and find the leftmost bit (MSB) that is set. From that point onwards, we flip every bit till we reach the rightmost bit (LSB). To flip a bit, we can use `^ 1` (XOR 1) opera... | 58 | 0 | [] | 6 |
number-complement | 3 line pure C | 3-line-pure-c-by-osamurai-4wpz | \nint findComplement(long num) {\n long i;\n for(i=1;i<=num;i*=2) num^=i; \n return num;\n}\n\nI basically check every bit of number by XOR'ing it with | osamurai | NORMAL | 2017-02-03T02:46:22.474000+00:00 | 2018-10-20T02:52:26.499737+00:00 | 4,783 | false | ```\nint findComplement(long num) {\n long i;\n for(i=1;i<=num;i*=2) num^=i; \n return num;\n}\n```\nI basically check every bit of number by XOR'ing it with appropriate power of 2 which leads to its invertion.\nFor example:\n```\nEntered: 4=>100;\n100 ^ 001 = 101;\n101 ^ 010 = 111;\n111 ^ 100 = 011;\nOut: ... | 55 | 1 | [] | 9 |
number-complement | Java | 0 ms | 1 liner | Explained | java-0-ms-1-liner-explained-by-prashant4-yurh | Idea:\n Flip all bits using negation operator (~) [read more here]\n Bitwise AND (&) with a bit mask of size n whose all bits are set, where n = number of bits | prashant404 | NORMAL | 2021-12-27T02:26:39.541164+00:00 | 2021-12-27T05:48:52.163304+00:00 | 8,003 | false | **Idea:**\n* Flip all bits using negation operator (~) [[read more here](https://www.ibm.com/docs/en/i/7.1?topic=expressions-bitwise-negation-operator)]\n* Bitwise AND (&) with a bit mask of size n whose all bits are set, where n = number of bits in `num`\n**Example:**\n```\nnum = 5\n num binary = 0...0101\n ~num bina... | 51 | 6 | ['Java'] | 7 |
number-complement | [Python3] Easy One line Code -with Explanation | python3-easy-one-line-code-with-explanat-9f83 | Here\'s the code:\npython\nclass Solution:\n def findComplement(self, num: int) -> int:\n return num^(2**(len(bin(num)[2:]))-1)\n\nWhat does it mean?\ | xhon9 | NORMAL | 2020-05-04T08:13:10.626298+00:00 | 2020-05-04T08:40:02.765365+00:00 | 4,369 | false | Here\'s the code:\n```python\nclass Solution:\n def findComplement(self, num: int) -> int:\n return num^(2**(len(bin(num)[2:]))-1)\n```\nWhat does it mean?\nThe complement of a number is computable by "flipping" all the bits in his binary form.\nIn other words, that\'s nothing more than a **bitwise XOR with a... | 44 | 1 | ['Python3'] | 9 |
number-complement | DETAILED EXPLANATION Java XOR Method Easy To Understand | detailed-explanation-java-xor-method-eas-jxnj | Let\'s say the input is num = 5 = 101 in binary\nOur mask needs to be 111 and then we will perform a XOR operation. The XOR operation says return TRUE (1) only | milan102 | NORMAL | 2018-08-09T05:45:49.487669+00:00 | 2018-09-04T22:36:25.732753+00:00 | 1,964 | false | Let\'s say the input is num = 5 = 101 in binary\nOur mask needs to be 111 and then we will perform a XOR operation. The XOR operation says return TRUE (1) only if one of the bits is true, else return FALSE (0). This means that when we XOR a 1 and a 1 bit, we will get 0. If we XOR a 1 and 0 bit, we will get 1. Thus effe... | 35 | 0 | [] | 5 |
number-complement | Javascript Solution - without converting to binary | javascript-solution-without-converting-t-t0t0 | Let\'s look to rundom binary number, for example: 10011.\nReverse of this number = 01100.\nLook, it\'s equal: 100000 - 10011 - 1.\n\nIdea: find the minimum near | nkuklina | NORMAL | 2020-05-04T18:18:38.132024+00:00 | 2020-05-04T18:20:32.814031+00:00 | 1,130 | false | Let\'s look to rundom binary number, for example: `10011`.\nReverse of this number = `01100`.\nLook, it\'s equal: `100000 - 10011 - 1`.\n\n**Idea:** find the minimum nearest number greater than `num` (power of 2)\n\n```\n/**\n * @param {number} num\n * @return {number}\n */\nvar findComplement = function(num) { \n ... | 23 | 0 | ['JavaScript'] | 2 |
number-complement | One line solution C++ | one-line-solution-c-by-dastijr-25yv | \nclass Solution {\npublic:\n int findComplement(int num) {\n return (pow(2,floor(log2(num))+1)-1)-num;\n }\n};\n\n\nHere, floor(log2(num))+1 gives | dastijr | NORMAL | 2021-12-27T08:12:32.282747+00:00 | 2023-01-05T04:52:00.000829+00:00 | 2,272 | false | ```\nclass Solution {\npublic:\n int findComplement(int num) {\n return (pow(2,floor(log2(num))+1)-1)-num;\n }\n};\n```\n\nHere, **floor(log2(num))+1** gives us the number of bits in integer **num**.\nThe maximum value obtained with this number of bits is **pow(2,no of bits)-1**.\nWhen we **subtract from m... | 22 | 0 | ['Bit Manipulation', 'C++'] | 3 |
number-complement | Explained | Easy to understand | Faster than 99.58% | Simple | Bit manipulation | Python Solution | explained-easy-to-understand-faster-than-57up | Later I found that this solution correponds to the second approach mentioned in the solution\n\nHere, in this soution, we are just making another bit variable t | mrmagician | NORMAL | 2020-04-02T17:23:03.693499+00:00 | 2020-04-02T17:23:53.135162+00:00 | 1,755 | false | ##### Later I found that this solution correponds to the second approach mentioned in the solution\n\nHere, in this soution, we are just making another bit variable to be full of 1\'s upto the length of bits in num and then simply returning the XOR of two\nnum = 5 = 101\nbit ===== 111\nAns ==== 010 = 2\n\n```\ndef find... | 22 | 1 | ['Bit Manipulation', 'Python', 'Python3'] | 3 |
number-complement | clz finds bit length then xor->1 line||0ms Beats 100% | clz-finds-bit-length-then-xor-1-line0ms-n6b2y | Intuition\n Describe your first thoughts on how to solve this problem. \ncount how many bits the number num needs by using clz or countl_zero(since C++20)\nThen | anwendeng | NORMAL | 2024-08-22T00:29:53.701966+00:00 | 2024-08-22T10:02:13.017192+00:00 | 8,661 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\ncount how many bits the number num needs by using clz or countl_zero(since C++20)\nThen xor with 0x7fffffff then & (1<<bitLen)-1 if bitLen<31\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Count bLen by using `bL... | 21 | 4 | ['Bit Manipulation', 'Bitmask', 'C++', 'Python3'] | 6 |
number-complement | Java Bit masking 100% faster | java-bit-masking-100-faster-by-saiyancod-pseu | \nclass Solution {\n public int findComplement(int num) {\n int c = 0, t = num;\n\t\t//First, you need to find how many bits are present in the given | saiyancoder | NORMAL | 2020-11-02T17:18:49.975120+00:00 | 2020-11-02T17:19:07.221184+00:00 | 1,638 | false | ```\nclass Solution {\n public int findComplement(int num) {\n int c = 0, t = num;\n\t\t//First, you need to find how many bits are present in the given number.\n while(t>0) {\n t = t>>1;\n c++;\n }\n\t\t//Now after that, create a mask of 1\'s about the size of num.\n\t\t//... | 20 | 0 | ['Java'] | 1 |
number-complement | Python O( lg n ) XOR masking. [ w' explanation ] 有中文解析專欄 | python-o-lg-n-xor-masking-w-explanation-p55sz | Python O( log n ) sol. based on XOR masking. \n\n\u4E2D\u6587\u89E3\u6790\u5C08\u6B04\n\n---\n\nExample explanation\n\n---\nExample_#1\n\ninput: 5\n\n5 = 0b 101 | brianchiang_tw | NORMAL | 2020-01-23T03:47:35.110267+00:00 | 2024-08-22T15:22:16.394013+00:00 | 2,181 | false | Python O( log n ) sol. based on XOR masking. \n\n[\u4E2D\u6587\u89E3\u6790\u5C08\u6B04](https://vocus.cc/article/66c6eddefd89780001e679b8)\n\n---\n\nExample explanation\n\n---\nExample_#1\n\ninput: **5**\n\n5 = 0b **101**\n**bits length** of 5 = **3**\n**masking** = **2^3 -1** = 8 - 1 = **7** = 0b **111**\n\n5 = 0b **1... | 20 | 0 | ['Bit Manipulation', 'Bitmask', 'Python', 'Python3'] | 3 |
number-complement | Simple Java Code ☠️ | simple-java-code-by-abhinandannaik1717-ddqa | \n# Code\njava []\nclass Solution {\n public int findComplement(int num) {\n String str = Integer.toBinaryString(num);\n String res = "";\n | abhinandannaik1717 | NORMAL | 2024-08-22T02:27:12.532532+00:00 | 2024-08-22T02:27:12.532561+00:00 | 5,510 | false | \n# Code\n```java []\nclass Solution {\n public int findComplement(int num) {\n String str = Integer.toBinaryString(num);\n String res = "";\n for(int i=0;i<str.length();i++){\n if(str.charAt(i) == \'0\'){\n res += \'1\';\n }\n else{\n ... | 18 | 0 | ['String', 'Java'] | 6 |
number-complement | Java one line solution without using AND (&) or XOR (^) | java-one-line-solution-without-using-and-zjvz | To find complement of num = 5 which is 101 in binary.\nFirst ~num gives ...11111010 but we only care about the rightmost 3 bits.\nThen to erase the 1s before 01 | yuxiangmusic | NORMAL | 2017-01-10T04:29:50.621000+00:00 | 2018-09-20T18:04:03.945284+00:00 | 7,649 | false | To find complement of ```num = 5``` which is ```101``` in binary.\nFirst ```~num``` gives ```...11111010``` but we only care about the rightmost 3 bits.\nThen to erase the ```1```s before ```010``` we can add ```1000```\n\n```\n public int findComplement(int num) {\n return ~num + (Integer.highestOneBit(num) ... | 18 | 0 | [] | 4 |
number-complement | Beats 100% || O(32) Time O(1) Space || Easy Explanation + Code | beats-100-o32-time-o1-space-easy-explana-xim3 | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | Garv_Virmani | NORMAL | 2024-08-22T02:12:29.346987+00:00 | 2024-08-22T02:12:29.347017+00:00 | 7,120 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 17 | 4 | ['C++'] | 5 |
number-complement | Easy C++ | easy-c-by-rtom09-7la8 | Thought process is that you have to keep one number shift to left until it can no longer be shifted. At the same time, you can right shift by 1 for a number i a | rtom09 | NORMAL | 2017-01-10T18:21:46.559000+00:00 | 2017-01-10T18:21:46.559000+00:00 | 4,609 | false | Thought process is that you have to keep one number shift to left until it can no longer be shifted. At the same time, you can right shift by 1 for a number i and take the XOR, which leads to the opposite complement.\n\n```\nclass Solution {\npublic:\n int findComplement(int num) {\n int copy = num;\n ... | 17 | 1 | ['Bit Manipulation', 'C'] | 1 |
number-complement | Oneline C++ Solution | oneline-c-solution-by-kevin36-hlrj | ~~For some strange reason when I submit it fails the last test case,but if you run that test on its own in the custom testcase it passes. So I think something i | kevin36 | NORMAL | 2017-01-08T05:02:55.445000+00:00 | 2017-01-08T05:02:55.445000+00:00 | 6,016 | false | ~~For some strange reason when I submit it fails the last test case,but if you run that test on its own in the custom testcase it passes. So I think something is wrong with the testing.~~\n\n```class Solution {\npublic:\n int findComplement(int num) {\n return ~num & ((1 <<(int)log2(num))-1);\n }\n}; | 15 | 1 | [] | 7 |
number-complement | Work of art | work-of-art-by-ryanbaker1228-wdtc | Intuition\nThis is a work of art and if you disagree it\'s your fault.\nRespectfully, me\n\n# Approach\nGod invaded my head\n\n# Complexity\n- Time complexity:\ | ryanbaker1228 | NORMAL | 2024-08-22T01:39:11.635372+00:00 | 2024-08-22T01:39:11.635416+00:00 | 1,121 | false | # Intuition\nThis is a work of art and if you disagree it\'s your fault.\nRespectfully, me\n\n# Approach\nGod invaded my head\n\n# Complexity\n- Time complexity:\nWho cares its cool\n\n- Space complexity:\nWho cares its cool\n\n# Code\n```c []\nint findComplement(int num)\n{\n int n = num; return ~n & ((num |= (num ... | 13 | 0 | ['C'] | 8 |
number-complement | Beat 100% -> 0ms | C++ | T.C. -> O(logn) | S.C. -> O(1) | beat-100-0ms-c-tc-ologn-sc-o1-by-abhishe-g550 | Intuition\n Describe your first thoughts on how to solve this problem. \nThe problem requires finding the complement of a given integer num, where the complemen | abhishek_k11 | NORMAL | 2024-08-22T00:05:54.988152+00:00 | 2024-08-22T00:26:37.032042+00:00 | 1,709 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe problem requires finding the complement of a given integer num, where the complement is obtained by flipping all bits in the binary representation of num (i.e., converting 1s to 0s and 0s to 1s). The integer num will have no leading z... | 13 | 2 | ['C++'] | 0 |
number-complement | ✅ Easy Solution with Explanation | 🛑2 Approaches🛑 | Without Bit Manipulation | 🔥Beats 100%🔥 | easy-solution-with-explanation-2-approac-ujl2 | See the pattern?\n\n\nNumber Binary Complement Complement Value\n1 = 1 -> 0 = 0\n\n2 = 10 -> 01 = 1\n3 | fxce | NORMAL | 2023-09-02T17:01:06.067756+00:00 | 2024-08-22T04:39:41.359531+00:00 | 1,374 | false | See the pattern?\n\n```\nNumber Binary Complement Complement Value\n1 = 1 -> 0 = 0\n\n2 = 10 -> 01 = 1\n3 = 11 -> 00 = 0\n\n4 = 100 -> 011 = 3\n5 = 101 -> 010 = 2\n6 = 110 -> 001 = 1\n7 ... | 12 | 0 | ['Bit Manipulation', 'Java'] | 0 |
number-complement | ♾️ C++ | ✅100% Beats | ✅Full Explanation | 476. Number Complement | c-100-beats-full-explanation-476-number-ff3j7 | :) Please Upvote If You Like the Solution :)\n\n# Approach\n1. We know that we need to complement. For that we need to change 0 to 1 and 1 to 0.\n\n2. We need t | AnantKumawat22 | NORMAL | 2023-05-26T13:30:11.904989+00:00 | 2023-05-26T13:30:11.905022+00:00 | 894 | false | # :) Please Upvote If You Like the Solution :)\n\n# Approach\n1. We know that we need to complement. For that we need to change `0` to `1` and `1` to `0`.\n\n2. We need to think, what can we use here from our bitwise operators `(i.e &, |, ^, ~)`.\n\n3. Suppose we have,\n\n```\nEx. n = 10, binary-> 1010\n 1 0 1 0\n ... | 11 | 0 | ['Bit Manipulation', 'C', 'Bitmask', 'C++'] | 0 |
number-complement | [C++] O(1) using bitwise operator with explanation | c-o1-using-bitwise-operator-with-explana-tw2o | \n/*\nnum = 00000110\nmask = 00000111\n~num = 11111001\nmask & ~num = 00000001\n*/\nint findComplement( int num ) {\n\tint mask = 0, t | sonugiri | NORMAL | 2020-05-04T07:33:43.006195+00:00 | 2020-05-04T07:41:09.299846+00:00 | 1,992 | false | ```\n/*\nnum = 00000110\nmask = 00000111\n~num = 11111001\nmask & ~num = 00000001\n*/\nint findComplement( int num ) {\n\tint mask = 0, tmp=num;\n\twhile( tmp ) {\n\t\ttmp = tmp >> 1;\n\t\tmask = mask << 1;\n\t\tmask = mask | 1;\n\t}\n\treturn ~num & mask;\n}\n``` | 11 | 0 | [] | 10 |
number-complement | Python XOR one line - no loops | python-xor-one-line-no-loops-by-w2schmit-x8vn | \nreturn num ^ (2**num.bit_length() - 1)\n | w2schmitt | NORMAL | 2019-07-01T04:29:08.634800+00:00 | 2019-07-01T04:31:33.799954+00:00 | 880 | false | ```\nreturn num ^ (2**num.bit_length() - 1)\n``` | 11 | 0 | ['Bit Manipulation', 'Python'] | 2 |
number-complement | Easy and simplest aproach , Easy to understand | easy-and-simplest-aproach-easy-to-unders-x0od | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | raeezrazz | NORMAL | 2024-08-22T04:56:27.848659+00:00 | 2024-08-22T04:56:27.848717+00:00 | 1,116 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 10 | 5 | ['TypeScript', 'JavaScript'] | 3 |
number-complement | Easy Solution | Beats 100% | easy-solution-beats-100-by-sachinonly-8tlk | Code\npython []\nclass Solution(object):\n def findComplement(self, num):\n def decimal_to_binary(n):\n if n == 0:\n return | Sachinonly__ | NORMAL | 2024-08-22T00:15:38.315306+00:00 | 2024-08-22T00:15:38.315326+00:00 | 6,058 | false | # Code\n```python []\nclass Solution(object):\n def findComplement(self, num):\n def decimal_to_binary(n):\n if n == 0:\n return "0"\n binary = ""\n while n > 0:\n binary = str(n % 2) + binary\n n = n // 2\n return binary... | 10 | 0 | ['Bit Manipulation', 'Python', 'C++', 'Java', 'Python3'] | 4 |
number-complement | 2 ways to solve in Javascript | 2-ways-to-solve-in-javascript-by-yeuhoah-qbnd | Code\n\n/**\n * @param {number} num\n * @return {number}\n */\nvar findComplement = function(num) {\n // -- Solution 1:\n // let s = num.toString(2);\n | yeuhoahuuco | NORMAL | 2024-04-09T09:05:32.747299+00:00 | 2024-04-09T09:05:32.747342+00:00 | 285 | false | # Code\n```\n/**\n * @param {number} num\n * @return {number}\n */\nvar findComplement = function(num) {\n // -- Solution 1:\n // let s = num.toString(2);\n // let s1 = \'\';\n // for(let i = 0; i < s.length; i++)\n // {\n // s1 += (s[i] == \'0\') ? \'1\' : \'0\';\n // }\n // return parseInt... | 10 | 0 | ['JavaScript'] | 3 |
number-complement | [Python] O(1) solution, explained | python-o1-solution-explained-by-dbabiche-xzdl | There is very smart solution, where we spread the highest 1-bit onto all the lower bits. Try to do the following operations, see https://leetcode.com/problems/n | dbabichev | NORMAL | 2021-12-27T08:22:36.361024+00:00 | 2021-12-27T08:22:36.361054+00:00 | 542 | false | There is very smart solution, where we spread the highest 1-bit onto all the lower bits. Try to do the following operations, see https://leetcode.com/problems/number-of-1-bits/discuss/1044775/python-n-and-(n-1)-trick-explained for more details, idea is similar.\n\n#### Complexity\nIt is just `5` operations we need to d... | 10 | 2 | ['Bit Manipulation'] | 1 |
number-complement | Possibly, the easiest way (Java) | possibly-the-easiest-way-java-by-akimovv-sxtz | Just replace and that\'s it\n\nclass Solution {\n public int findComplement(int num) {\n String binary = Integer.toBinaryString(num);\n binary | akimovve | NORMAL | 2020-05-06T09:57:19.441010+00:00 | 2020-05-06T09:57:19.441046+00:00 | 571 | false | Just replace and that\'s it\n```\nclass Solution {\n public int findComplement(int num) {\n String binary = Integer.toBinaryString(num);\n binary = binary\n .replace("0", "2")\n .replace("1", "0")\n .replace("2", "1");\n return Integer.parseInt(binary... | 10 | 1 | ['Java'] | 0 |
number-complement | TypeScript, Runtime 42 ms Beats 100.00%, Memory 50.24 MB Beats 85.25% | typescript-runtime-42-ms-beats-10000-mem-78nq | Intuition\nThe intuition behind this solution is to directly flip all the bits of the binary representation of num using a mask. The mask is created by setting | r9n | NORMAL | 2024-08-22T00:10:51.803982+00:00 | 2024-08-22T00:10:51.804001+00:00 | 46 | false | # Intuition\nThe intuition behind this solution is to directly flip all the bits of the binary representation of num using a mask. The mask is created by setting all bits to 1 up to the highest bit of num. XORing num with this mask effectively inverts all the bits, giving the complement. This approach minimizes operati... | 9 | 0 | ['TypeScript'] | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.