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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
longest-substring-without-repeating-characters | Swift Time Exceeded Fix | swift-time-exceeded-fix-by-vladinecko-eldj | The "optimized" solution still runs over the acceptable time limit when the solution is delivered in Swift. I did a quick profiling session and realized the pro | vladinecko | NORMAL | 2019-05-07T06:51:05.943333+00:00 | 2019-05-07T06:54:31.790886+00:00 | 993 | false | The "optimized" solution still runs over the acceptable time limit when the solution is delivered in Swift. I did a quick profiling session and realized the problem is in Swift\'s implementation of String and how it accesses information about the underlying characters. \n\n {\n unordered_set<char>sub;//set to store occoured character\n int left=0, | priyamesh28 | NORMAL | 2021-09-06T18:02:38.541872+00:00 | 2021-09-06T18:02:38.541925+00:00 | 1,230 | false | ```\nclass Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n unordered_set<char>sub;//set to store occoured character\n int left=0,right=0; //two pointers to navigate\n int max_size=0;\n while(left<s.size() && right<s.size())\n {\n //if the char is not in ... | 17 | 1 | ['C', 'Ordered Set'] | 1 |
longest-substring-without-repeating-characters | Go solution | go-solution-by-waydi1-9acj | \nfunc lengthOfLongestSubstring(s string) int {\n start := 0\n longest := 0\n used := map[byte]int{}\n \n for i := 0; i < len(s); i++ {\n | waydi1 | NORMAL | 2021-01-10T11:38:09.566724+00:00 | 2021-01-10T11:38:09.566755+00:00 | 1,998 | false | ```\nfunc lengthOfLongestSubstring(s string) int {\n start := 0\n longest := 0\n used := map[byte]int{}\n \n for i := 0; i < len(s); i++ {\n c := s[i]\n \n if _, ok := used[c]; ok && used[c] >= start {\n start = used[c] + 1\n }\n \n longest = max(longe... | 17 | 0 | ['Go'] | 1 |
longest-substring-without-repeating-characters | [VIDEO] Visualization of O(n) Sliding Window Approach | video-visualization-of-on-sliding-window-evai | https://youtu.be/pY2dYa1m2VM\n\nA brute force solution would first require finding every possible substring, which would run in O(n2) time. We\'re not done yet | AlgoEngine | NORMAL | 2024-10-04T21:26:50.811575+00:00 | 2024-10-04T21:26:50.811595+00:00 | 2,128 | false | https://youtu.be/pY2dYa1m2VM\n\nA brute force solution would first require finding every possible substring, which would run in O(n<sup>2</sup>) time. We\'re not done yet though, because we now have to check every substring for duplicate characters by iterating through every substring. Each check for duplicate charac... | 16 | 0 | ['Hash Table', 'String', 'Sliding Window', 'Python', 'Python3'] | 0 |
longest-substring-without-repeating-characters | C++|Sliding Window | Hash Map |O(n) | csliding-window-hash-map-on-by-xahoor72-b6qk | Intuition\n Describe your first thoughts on how to solve this problem. \nIdea is to use a map and check when there is a duplicate remove it and maintain the cou | Xahoor72 | NORMAL | 2023-02-09T19:05:43.489167+00:00 | 2023-02-10T08:36:53.609262+00:00 | 4,327 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nIdea is to use a map and check when there is a duplicate remove it and maintain the counter for max window size.\nThis tempate ca be used for multiple questions like:\n- https://leetcode.com/problems/maximum-erasure-value/description/\n# ... | 16 | 1 | ['Hash Table', 'String', 'Sliding Window', 'C++'] | 5 |
longest-substring-without-repeating-characters | python | python-by-vote4-w202 | \ndef lengthOfLongestSubstring(self, s: str) -> int:\n maxLength = 0\n dict = {}\n\n i,j = 0,0\n n = len(s)\n\n while(j < n): | vote4 | NORMAL | 2022-09-19T05:33:03.433631+00:00 | 2022-09-19T05:33:03.433679+00:00 | 1,115 | false | ```\ndef lengthOfLongestSubstring(self, s: str) -> int:\n maxLength = 0\n dict = {}\n\n i,j = 0,0\n n = len(s)\n\n while(j < n):\n c = s[j] \n \n dict[c] = 1 if not c in dict else dict[c] + 1\n \n \n if dict[c] > 1:... | 16 | 2 | [] | 1 |
longest-substring-without-repeating-characters | O(n) Solution in C++ || Sliding Window || HashMaps | on-solution-in-c-sliding-window-hashmaps-icsg | The idea here is pretty simple... we use a map to keep track of already visited characters...\nWe initialize another pointer (j) which gives us the starting ind | harshit7962 | NORMAL | 2022-06-10T03:04:47.835554+00:00 | 2022-06-10T03:48:28.810307+00:00 | 2,084 | false | The idea here is pretty simple... we use a map to keep track of already visited characters...\nWe initialize another pointer (j) which gives us the starting index of current window and we traverse through the string using pointer i, which indicated current index of our window...\n* If the character at ith index is not ... | 16 | 2 | ['C', 'Sliding Window', 'C++'] | 1 |
longest-substring-without-repeating-characters | Javascript Solution using Sliding Window in O(n) time (w/ explanation) | javascript-solution-using-sliding-window-t4qi | Explanation\n\nThe main method used for this problem is the sliding window technique. The sliding window is essentially 2 pointers that will help to keep track | AmehPls | NORMAL | 2021-11-26T17:15:27.163067+00:00 | 2021-11-27T16:39:19.058158+00:00 | 2,057 | false | ## Explanation\n\nThe main method used for this problem is the **sliding window** technique. The sliding window is essentially 2 pointers that will help to keep track the start and end of a substring. In this solution, this window will always contain a substring with no duplicate characters.\n\nHere are the brief steps... | 16 | 1 | ['Sliding Window', 'Ordered Set', 'JavaScript'] | 1 |
longest-substring-without-repeating-characters | 10-line O(n) easy Java solution, covering edge cases without extra code | 10-line-on-easy-java-solution-covering-e-8m04 | This problem is a basic sliding window problem, so we should have a left and a right index. We will let our right index be the iterator of the string and hold t | gargeemukherjee | NORMAL | 2021-06-07T11:35:40.848217+00:00 | 2021-06-07T11:55:15.535984+00:00 | 1,854 | false | This problem is a basic sliding window problem, so we should have a left and a right index. We will let our right index be the iterator of the string and hold the position of the current character we are at. The basic idea is to put the characters you visit in map with their index as the value. We want to find the last... | 16 | 0 | ['Sliding Window', 'Java'] | 1 |
longest-substring-without-repeating-characters | share my javaScript solution,i think it is easy to understand | share-my-javascript-solutioni-think-it-i-uv15 | ```\nvar lengthOfLongestSubstring = function (s) {\n var max=0,\n theSub=\'\'\n for(var i=0;i=0){ \n theSub= theSub.substring(idx+1) \n | masicheng | NORMAL | 2019-06-14T07:22:34.455176+00:00 | 2019-06-24T01:54:42.798754+00:00 | 2,507 | false | ```\nvar lengthOfLongestSubstring = function (s) {\n var max=0,\n theSub=\'\'\n for(var i=0;i<s.length;i++){\n const idx=theSub.indexOf(s[i])\n theSub+=s[i]\n if(idx>=0){ \n theSub= theSub.substring(idx+1) \n }\n if(theSub.length>max){\n max=theSub.len... | 16 | 0 | ['JavaScript'] | 2 |
longest-substring-without-repeating-characters | O(N) runtime , constant space solution. | on-runtime-constant-space-solution-by-13-kbzd | \nKeep track of the last index of each char. Scan s from left to right, if hit a previously encountered char, then reset the longest substring to start just aft | 1337beef | NORMAL | 2014-09-25T17:57:37+00:00 | 2014-09-25T17:57:37+00:00 | 3,695 | false | \nKeep track of the last index of each char. Scan s from left to right, if hit a previously encountered char, then reset the longest substring to start just after the last index of the seen char.\n\n int lengthOfLongestSubstring(const string& s) {\n int idx[256]; // indices of each char.\n ... | 16 | 0 | [] | 1 |
longest-substring-without-repeating-characters | Best Solution for Arrays 🚀 in C++, Python and Java || 100% working | best-solution-for-arrays-in-c-python-and-hekt | Intuition💡 To find the Longest Substring Without Repeating Characters, we use a sliding window approach. This method dynamically adjusts the window size to ensu | BladeRunner150 | NORMAL | 2025-01-11T05:54:56.103372+00:00 | 2025-01-11T05:54:56.103372+00:00 | 3,456 | false | # Intuition
💡 To find the **Longest Substring Without Repeating Characters**, we use a **sliding window** approach. This method dynamically adjusts the window size to ensure all characters inside the window are unique.
# Approach
👉 Use two pointers, `l` and `r`, to define a window over the string.
👉 Maintai... | 15 | 0 | ['Hash Table', 'String', 'Sliding Window', 'Python', 'C++', 'Java', 'Python3'] | 0 |
longest-substring-without-repeating-characters | Python sliding window (simple syntax) | python-sliding-window-simple-syntax-by-g-1by8 | Python sliding window. \n\n\nclass Solution(object):\n def lengthOfLongestSubstring(self, s):\n # create a window with left and right\n # keep | grapes42 | NORMAL | 2020-02-18T03:43:13.014802+00:00 | 2020-02-18T03:43:13.014850+00:00 | 2,039 | false | Python sliding window. \n\n```\nclass Solution(object):\n def lengthOfLongestSubstring(self, s):\n # create a window with left and right\n # keep a hash of elements already added\n left = 0\n right = 0\n seen = {} # keeps track of seen elements\n\n max_count = 0\n\n f... | 15 | 0 | ['Sliding Window', 'Python'] | 2 |
longest-substring-without-repeating-characters | Java | Sliding Window template | java-sliding-window-template-by-prashant-nzz9 | Algo:\n1. Use a hashMap to keep track of the latest index of each letter\n2. Keeping the left pointer at rest, move the right pointer by 1 letter at a time.\n3. | prashant404 | NORMAL | 2019-07-19T18:55:36.305442+00:00 | 2022-06-12T04:04:49.931852+00:00 | 4,967 | false | Algo:\n1. Use a hashMap to keep track of the latest index of each letter\n2. Keeping the left pointer at rest, move the right pointer by 1 letter at a time.\n3. When a repeating character is encountered, update the maxLength and move the left pointer to max{left pointer, old last occurence of this character as availabl... | 15 | 0 | ['Two Pointers', 'Sliding Window', 'Java'] | 2 |
longest-substring-without-repeating-characters | Accepted 16ms c++ DP solution, O(n), with bitmask to record the last position of each letter appears | accepted-16ms-c-dp-solution-on-with-bitm-9m2f | class Solution {\n public:\n int lengthOfLongestSubstring(std::string s) {\n std::vector<int> flag(256, -1);\n int start = 0, lo | prime_tang | NORMAL | 2015-05-30T11:40:10+00:00 | 2015-05-30T11:40:10+00:00 | 4,914 | false | class Solution {\n public:\n int lengthOfLongestSubstring(std::string s) {\n std::vector<int> flag(256, -1);\n int start = 0, longest = 0;\n for (int i = 0; i != s.size(); ++i) {\n start = std::max(start, flag[s[i]] + 1);\n flag[s[i]] = i;\n ... | 15 | 0 | [] | 3 |
longest-substring-without-repeating-characters | My simple c++ solution | my-simple-c-solution-by-kelseyzhou-ybbb | class Solution {\n public:\n int lengthOfLongestSubstring(string s) {\n vector<int> table(256, 0);\n int maxstr=0, track=0;\n for(int | kelseyzhou | NORMAL | 2016-02-24T16:49:13+00:00 | 2018-09-27T05:56:13.756352+00:00 | 4,847 | false | class Solution {\n public:\n int lengthOfLongestSubstring(string s) {\n vector<int> table(256, 0);\n int maxstr=0, track=0;\n for(int i=0;i<s.length();i++)\n {\n while(table[s[i]])table[s[track++]]=0;\n table[s[i]]=1;\n maxstr=max(maxstr, i-track+1)... | 15 | 1 | [] | 1 |
longest-substring-without-repeating-characters | JavaScript True O(n) Sliding Window with Explanation | javascript-true-on-sliding-window-with-e-dcmk | Complexity\n- Time complexity: O(n)\n- Space complexity: O(n)\n\n# Code\n\n/**\n * @param {string} s\n * @return {number}\n */\nfunction lengthOfLongestSubstrin | danorati | NORMAL | 2022-12-22T21:07:58.058462+00:00 | 2022-12-22T21:12:50.901627+00:00 | 4,483 | false | # Complexity\n- Time complexity: O(n)\n- Space complexity: O(n)\n\n# Code\n```\n/**\n * @param {string} s\n * @return {number}\n */\nfunction lengthOfLongestSubstring(inputString) {\n if (inputString.length == 0) return 0;\n\n let n = inputString.length;\n \n // starting index of current window substring\n ... | 14 | 0 | ['JavaScript'] | 1 |
longest-substring-without-repeating-characters | Rust Two Pointers with HashMap | rust-two-pointers-with-hashmap-by-minami-w7ce | I like the HashMap.insert function returning the old value :)\nrust\nuse std::collections::HashMap;\n\nimpl Solution {\n pub fn length_of_longest_substring(s | Minamikaze392 | NORMAL | 2022-06-10T02:36:31.654305+00:00 | 2022-06-10T02:36:31.654352+00:00 | 1,016 | false | I like the HashMap.insert function returning the old value :)\n```rust\nuse std::collections::HashMap;\n\nimpl Solution {\n pub fn length_of_longest_substring(s: String) -> i32 {\n let mut hash: HashMap<char, i32> = HashMap::new();\n let mut ans = 0;\n let mut lo = -1;\n for (hi, ch) in s... | 14 | 0 | ['Two Pointers', 'Rust'] | 1 |
longest-substring-without-repeating-characters | Java Simple Sliding Window Technique With Comments | java-simple-sliding-window-technique-wit-dlte | \n\n public int lengthOfLongestSubstring(String s) {\n int left = 0; // start of window\n int right = 0; // end of window (initially the same a | emerfan | NORMAL | 2021-12-15T09:27:46.842169+00:00 | 2021-12-15T09:28:12.806571+00:00 | 1,382 | false | ```\n\n public int lengthOfLongestSubstring(String s) {\n int left = 0; // start of window\n int right = 0; // end of window (initially the same as start so we can grab the first char)\n int result = 0; // var to store the length of the longest substring we have found so far\n HashSet<Cha... | 14 | 0 | ['Sliding Window', 'Java'] | 3 |
longest-substring-without-repeating-characters | ScanLeft | Scala | Concise Solution with Explanation | scanleft-scala-concise-solution-with-exp-qkcz | We would use scanLeft starting with initial value empty string("")\nNow we for Binary Operator op: (B, A) => B, we would provide substring function that would s | imran-sarwar | NORMAL | 2020-08-14T17:25:25.802168+00:00 | 2020-08-14T18:48:16.151785+00:00 | 999 | false | We would use scanLeft starting with initial value empty string("")\nNow we for Binary Operator op: (B, A) => B, we would provide substring function that would substring till it would find current character in previously calculated String, and we postfix the current character to current substring to start looking for fu... | 14 | 0 | ['Scala'] | 3 |
longest-substring-without-repeating-characters | O(N) C# Solution with simple code & explanation | on-c-solution-with-simple-code-explanati-muq2 | The idea is store index of each char in dictionary, if repeating char is encountered - start calculating from stored index, since there cannot be string greate | christris | NORMAL | 2019-02-27T02:46:09.739011+00:00 | 2019-02-27T02:46:09.739076+00:00 | 1,396 | false | The idea is store index of each char in dictionary, if repeating char is encountered - start calculating from stored index, since there cannot be string greater than string from character starting from any index before index of repeating char as in future there will be repeating char of stored index. This helps in avo... | 14 | 2 | [] | 3 |
longest-substring-without-repeating-characters | Java solution WITHOUT hashmap | java-solution-without-hashmap-by-gavinli-wip1 | The idea is pretty simple. We iterate thru the list once and we keep a pointer of where the current longest possible substring starts. During the iteration, we | gavinlinasd | NORMAL | 2015-09-10T08:33:24+00:00 | 2015-09-10T08:33:24+00:00 | 3,553 | false | The idea is pretty simple. We iterate thru the list once and we keep a pointer of where the current longest possible substring starts. During the iteration, we check if this last character is contained in the current substring. If so, move the ptr to the first index of the char at the string +1. Everytime we will compa... | 14 | 0 | ['Java'] | 3 |
longest-substring-without-repeating-characters | C Implementation | c-implementation-by-prabhatravi-xd1x | Approach\n Describe your approach to solving the problem. \nWe initialize an array charIndexMap to store the most recent index of each character encountered. We | prabhatravi | NORMAL | 2024-04-24T07:47:55.288700+00:00 | 2024-04-24T07:47:55.288721+00:00 | 1,973 | false | # Approach\n<!-- Describe your approach to solving the problem. -->\nWe initialize an array charIndexMap to store the most recent index of each character encountered. We use a size of 256 assuming ASCII characters and initialize all elements to -1.\nWe iterate through the characters of the input string s.\nIf a charact... | 13 | 0 | ['C'] | 0 |
longest-substring-without-repeating-characters | ✅Short || C++ || Java || PYTHON || JS || Explained Solution✔️ || Beginner Friendly ||🔥 | short-c-java-python-js-explained-solutio-k8om | read full article https://www.nileshblog.tech/longest-substring-without-repeating-characters/\n\nIntuition\nApproach\n1 window\n2 hashmap\n3 Two Pointer\n\nComp | amoddeshmukh844 | NORMAL | 2023-09-20T18:39:41.737413+00:00 | 2023-09-20T18:39:41.737438+00:00 | 2,981 | false | read full article https://www.nileshblog.tech/longest-substring-without-repeating-characters/\n\nIntuition\nApproach\n1 window\n2 hashmap\n3 Two Pointer\n\nComplexity\nO(n) and the space complexity is O(min(n, m))\n\nCode\nhttps://bit.ly/3iIALEY\n\n`, where `m = max(A)`\nSpace `O(m)`\n<br>\n\n**Java**\n```java\n public int countMaxOrSubsets(int[] A) {\... | 146 | 9 | [] | 27 |
count-number-of-maximum-bitwise-or-subsets | 🌟 Beats 96.00% 👏 || Step-by-Step Breakdown 💯🔥 | beats-9600-step-by-step-breakdown-by-wit-ehpy | \n\n## \uD83C\uDF1F Access Daily LeetCode Solutions Repo : click here\n\n---\n\n\n\n---\n\n# Intuition\nWhen we are asked to compute the maximum bitwise OR of s | withaarzoo | NORMAL | 2024-10-18T00:11:56.587131+00:00 | 2024-10-18T00:11:56.587161+00:00 | 25,790 | false | \n\n## **\uD83C\uDF1F Access Daily LeetCode Solutions Repo :** [click here](https://github.com/withaarzoo/LeetCode-Solutions)\n\n---\n\n\n\n## Solution 1. Bitmask\n\n1. Compute `goal` which is the maximum possible bitwise OR of a subset of `nums`, i.e. the bitwise OR of all the numbers in `nums`. \n2. Enumerate all non-empty subsets of `nums` using bitmask and compute the bi... | 43 | 4 | [] | 6 |
count-number-of-maximum-bitwise-or-subsets | Recursion via take or skip with/without Memo vs BitMask||Beats 100% | recursion-via-take-or-skip-withwithout-m-6vfh | Intuition\n Describe your first thoughts on how to solve this problem. \nIf you look at the constraints carefully, this computational $O(2^n)$ solution is in f | anwendeng | NORMAL | 2024-10-18T00:31:55.349954+00:00 | 2024-10-18T02:44:08.935249+00:00 | 5,817 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nIf you look at the constraints carefully, this computational $O(2^n)$ solution is in fact not slower than other possible solutions, since `1<=n<=16`.\n\nRecursion with/without memo can be solved with the argument take or skip; this recur... | 29 | 0 | ['Dynamic Programming', 'Bit Manipulation', 'Recursion', 'Memoization', 'C++'] | 10 |
count-number-of-maximum-bitwise-or-subsets | Java beats 100% | java-beats-100-by-noahjpark-u0sp | Intuition: Accumulate the maximum bitwise value from the array then apply the subset formula to accumulate all subsets that have that value.\n\n```\nclass Solut | noahjpark | NORMAL | 2021-10-17T04:03:20.382968+00:00 | 2021-10-17T04:03:20.382990+00:00 | 2,113 | false | Intuition: Accumulate the maximum bitwise value from the array then apply the subset formula to accumulate all subsets that have that value.\n\n```\nclass Solution {\n \n int res = 0, target = 0;\n \n public int countMaxOrSubsets(int[] nums) {\n for (int num : nums)\n target |= num;\n ... | 28 | 2 | [] | 2 |
count-number-of-maximum-bitwise-or-subsets | Python | Backtracking Pattern | python-backtracking-pattern-by-khosiyat-66l8 | see the Successfully Accepted Submission\n\n# Code\npython3 []\nfrom typing import List\n\nclass Solution:\n def countMaxOrSubsets(self, nums: List[int]) -> | Khosiyat | NORMAL | 2024-10-18T02:18:27.383555+00:00 | 2024-10-18T02:18:27.383590+00:00 | 1,983 | false | [see the Successfully Accepted Submission](https://leetcode.com/problems/count-number-of-maximum-bitwise-or-subsets/submissions/1425960007/?envType=daily-question&envId=2024-10-18)\n\n# Code\n```python3 []\nfrom typing import List\n\nclass Solution:\n def countMaxOrSubsets(self, nums: List[int]) -> int:\n # S... | 21 | 0 | ['Python3'] | 4 |
count-number-of-maximum-bitwise-or-subsets | Java | (Subset Problem) | beats 100% | java-subset-problem-beats-100-by-smanett-tnfh | \nclass Solution {\n public int countMaxOrSubsets(int[] nums) {\n \n subsets(nums, 0, 0);\n return count;\n }\n \n int count = | smanettone | NORMAL | 2021-10-17T04:03:31.206381+00:00 | 2021-10-17T07:15:45.484859+00:00 | 2,088 | false | ```\nclass Solution {\n public int countMaxOrSubsets(int[] nums) {\n \n subsets(nums, 0, 0);\n return count;\n }\n \n int count = 0;\n int maxOR = 0;\n \n private void subsets(int[] arr, int vidx, int OR){\n \n if(vidx == arr.length){\n \n if... | 19 | 1 | ['Bitmask', 'Java'] | 1 |
count-number-of-maximum-bitwise-or-subsets | Simple recursive solution | simple-recursive-solution-by-ayashi-5lm9 | Maximum Bitwise-OR is possible when we take bitwise-or of all the numbers.\n\nStep 1: Calculate the bitwise of all the numbers.\nStep 2: Find all bitwise of all | ayashi | NORMAL | 2021-10-17T04:03:07.128382+00:00 | 2021-10-17T04:04:22.023196+00:00 | 2,464 | false | **Maximum Bitwise-OR** is possible when we take **bitwise-or of all the numbers.**\n\nStep 1: Calculate the bitwise of all the numbers.\nStep 2: Find all bitwise of all the possible subsets recursively.\nStep 3: Simply compare the values of step 2 with step 1\n\n\'\'\'\nclass Solution {\npublic:\n \n int subset(v... | 14 | 2 | ['Recursion', 'C'] | 2 |
count-number-of-maximum-bitwise-or-subsets | The actual optimal solution. O(n*maxOR) time, O(1) space | the-actual-optimal-solution-onmaxor-time-xw8d | Approach\nFind the maximum OR value, then efficiently count the number of subsets of the array that do not have the maximum OR value using inclusion-exclusion.\ | TheodoreGossett | NORMAL | 2024-10-18T00:47:56.040682+00:00 | 2024-10-18T08:02:16.992094+00:00 | 2,008 | false | # Approach\nFind the maximum OR value, then efficiently count the number of subsets of the array that do not have the maximum OR value using inclusion-exclusion.\n\nHere is a good resource to learn about the principle of inclusion-exclusion: https://artofproblemsolving.com/wiki/index.php/Principle_of_Inclusion-Exclusio... | 13 | 0 | ['C++'] | 6 |
count-number-of-maximum-bitwise-or-subsets | C++ | Beginner friendly | Bitmask | Checking all subsets | c-beginner-friendly-bitmask-checking-all-9s0j | Feel free to comment \n\nclass Solution {\npublic:\n int countMaxOrSubsets(vector<int>& nums) {\n \n int i,j,max_possible_or=0,n=nums.size(),an | emiya100 | NORMAL | 2021-10-17T04:02:34.641618+00:00 | 2021-10-17T04:07:33.562077+00:00 | 1,304 | false | Feel free to comment \n```\nclass Solution {\npublic:\n int countMaxOrSubsets(vector<int>& nums) {\n \n int i,j,max_possible_or=0,n=nums.size(),ans=0;\n \n //maximum possible or=or of all number in array\n for(i=0;i<n;i++)\n {\n max_possible_or=nums[i]|max_possibl... | 12 | 0 | ['C', 'C++'] | 2 |
count-number-of-maximum-bitwise-or-subsets | [Python3] top-down dp | python3-top-down-dp-by-ye15-753w | \n\nclass Solution:\n def countMaxOrSubsets(self, nums: List[int]) -> int:\n target = reduce(or_, nums)\n \n @cache\n def fn(i, m | ye15 | NORMAL | 2021-10-17T04:04:16.003691+00:00 | 2021-10-17T04:04:16.003738+00:00 | 1,860 | false | \n```\nclass Solution:\n def countMaxOrSubsets(self, nums: List[int]) -> int:\n target = reduce(or_, nums)\n \n @cache\n def fn(i, mask): \n """Return number of subsets to get target."""\n if mask == target: return 2**(len(nums)-i)\n if i == len(nums): ret... | 11 | 0 | ['Python3'] | 2 |
count-number-of-maximum-bitwise-or-subsets | C++ || Easy Pick/Not Pick pattern✅✅✅ | c-easy-picknot-pick-pattern-by-arunk_lee-t5ck | Intuition\nThe problem involves finding the number of subsets in which the bitwise OR of all elements equals the maximum possible OR of the entire array. The fi | arunk_leetcode | NORMAL | 2024-10-18T05:01:54.675315+00:00 | 2024-10-18T05:01:54.675342+00:00 | 2,936 | false | # Intuition\nThe problem involves finding the number of subsets in which the bitwise OR of all elements equals the maximum possible OR of the entire array. The first intuition is to generate all subsets and compute their OR values, then compare each subset\'s OR value with the maximum OR that can be achieved by conside... | 10 | 0 | ['Dynamic Programming', 'Recursion', 'C++'] | 6 |
count-number-of-maximum-bitwise-or-subsets | Optimized C++ Approach with Explanation | optimized-c-approach-with-explanation-by-3dbh | Intuition\n Describe your first thoughts on how to solve this problem. \nThe bitwise OR operation\'s result always has ith bit set, whenever any one of the bits | Ankit_Rupal | NORMAL | 2022-10-09T11:39:20.146779+00:00 | 2023-01-03T19:53:56.692693+00:00 | 639 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe bitwise OR operation\'s result always has ith bit set, whenever any one of the bits is set. Thus, the maximum possible value of the bitwise OR of any subset of array a is the bitwise OR of array a itself!\nNow the question boils down ... | 10 | 0 | ['Backtracking', 'C++'] | 0 |
count-number-of-maximum-bitwise-or-subsets | ✅ One Line Solution | one-line-solution-by-mikposp-o80x | (Disclaimer: this is not an example to follow in a real project - it is written for fun and training mostly)\n\n# Code #1.1 - Recursive\nTime complexity: O(2^n) | MikPosp | NORMAL | 2024-10-18T09:16:40.508299+00:00 | 2024-10-18T11:16:35.710569+00:00 | 613 | false | (Disclaimer: this is not an example to follow in a real project - it is written for fun and training mostly)\n\n# Code #1.1 - Recursive\nTime complexity: $$O(2^n)$$. Space complexity: $$O(n)$$.\n```python3\nclass Solution:\n def countMaxOrSubsets(self, a: List[int]) -> int:\n return (f:=lambda i,o,O=reduce(or... | 9 | 0 | ['Array', 'Backtracking', 'Bit Manipulation', 'Recursion', 'Memoization', 'Combinatorics', 'Enumeration', 'Python', 'Python3'] | 1 |
count-number-of-maximum-bitwise-or-subsets | Easy C++ solution | DP | With Comments | easy-c-solution-dp-with-comments-by-iash-09gl | \nclass Solution {\npublic:\n #define maxN 17\n #define maxM (1<<17)\n\n int dp[maxN][maxM];\n bool v[maxN][maxM];\n int findCnt(vector<int> arr, | iashi_g | NORMAL | 2021-10-17T04:09:19.925681+00:00 | 2021-10-17T04:09:19.925716+00:00 | 1,605 | false | ```\nclass Solution {\npublic:\n #define maxN 17\n #define maxM (1<<17)\n\n int dp[maxN][maxM];\n bool v[maxN][maxM];\n int findCnt(vector<int> arr, int start, int curr, int n, int maxor)\n{\n // Base case\n if (start == n) {\n return (curr == maxor);\n }\n \n if (v[start][curr])\n ... | 9 | 1 | ['Dynamic Programming', 'C'] | 3 |
count-number-of-maximum-bitwise-or-subsets | 💡 | O(2^n) | C++ 7ms| Java 8ms | Efficient Backtracking 🧠 | | o2n-c-7ms-java-8ms-efficient-backtrackin-ky0f | \n---\n\n> # Intuition\nWe need to calculate the maximum bitwise OR possible from any subset of the given numbers. Once we identify that, the task is to count h | user4612MW | NORMAL | 2024-10-18T04:02:33.044410+00:00 | 2024-10-18T04:02:33.044438+00:00 | 1,479 | false | #\n---\n\n> # Intuition\nWe need to calculate the maximum bitwise OR possible from any subset of the given numbers. Once we identify that, the task is to count how many subsets achieve this maximum. We can use a backtracking (DFS) approach to explore all subsets, keeping track of the current bitwise OR. If the OR match... | 8 | 0 | ['C++', 'Java', 'Python3'] | 4 |
count-number-of-maximum-bitwise-or-subsets | 💥Runtime beats 100.00%, memory beats 94.44% [EXPLAINED] | runtime-beats-10000-memory-beats-9444-ex-0ye9 | Intuition\nFind subsets of an array that yield the highest possible bitwise OR. The bitwise OR combines bits of numbers, resulting in a number that has bits set | r9n | NORMAL | 2024-10-18T04:40:18.345346+00:00 | 2024-10-18T04:40:18.345384+00:00 | 34 | false | # Intuition\nFind subsets of an array that yield the highest possible bitwise OR. The bitwise OR combines bits of numbers, resulting in a number that has bits set to 1 wherever any of the numbers have bits set to 1. Understanding how subsets interact to achieve this maximum OR helps us count how many different combinat... | 6 | 0 | ['C#'] | 0 |
count-number-of-maximum-bitwise-or-subsets | Here's a simple and well- explained Dart solution of the problem. | heres-a-simple-and-well-explained-dart-s-uskb | **Bold****# 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# Complex | _abhiramks | NORMAL | 2024-10-18T04:13:50.974967+00:00 | 2024-10-18T04:13:50.974990+00:00 | 34 | false | ******Bold******# 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, ... | 6 | 0 | ['Dart'] | 1 |
count-number-of-maximum-bitwise-or-subsets | ✅✅Easiest & Best Solution in C++ || O(1) SC💯✅ | easiest-best-solution-in-c-o1-sc-by-adis-0u35 | Code\n### Please Upvote if u liked my Solution\uD83E\uDD17\n\nclass Solution {\npublic:\n int count=0;\n void calculate(int ind, vector<int>& nums, int si | aDish_21 | NORMAL | 2022-10-04T10:04:51.903497+00:00 | 2023-04-10T08:16:43.927937+00:00 | 877 | false | # Code\n### Please Upvote if u liked my Solution\uD83E\uDD17\n```\nclass Solution {\npublic:\n int count=0;\n void calculate(int ind, vector<int>& nums, int size, int bitOR, int x){\n if(ind==size){\n if(x==bitOR)\n count++;\n return;\n }\n calculate(ind+1... | 6 | 0 | ['Array', 'Backtracking', 'Bit Manipulation', 'C++'] | 0 |
count-number-of-maximum-bitwise-or-subsets | JAVA Solution: well-explained. Easy to understand | java-solution-well-explained-easy-to-und-73nr | Hi there ! \nIdea of this solution could be devided on two parts \n1. Using backtracking algorithm find all possible subsets. I would highly suggest to solve 78 | sgusache | NORMAL | 2022-05-09T19:33:37.815876+00:00 | 2022-05-09T19:45:44.410247+00:00 | 675 | false | Hi there ! \nIdea of this solution could be devided on two parts \n1. Using backtracking algorithm find all possible subsets. I would highly suggest to solve [```78. Subsets``` ](https://leetcode.com/problems/subsets/)first. \n2. Use ArrayList to store current betwise OR of subset \n\n## Let\'s take a look at this exam... | 6 | 0 | ['Backtracking', 'Java'] | 1 |
count-number-of-maximum-bitwise-or-subsets | C++ | easy solution with explanation. beats 100% cpp submission | c-easy-solution-with-explanation-beats-1-6799 | The problem is another version of subset sum. Here, we need to calculate OR of every non empty subset instead of sum.\n\nTo generate all possible subset, each s | solaimanhosen | NORMAL | 2021-10-17T04:42:27.496402+00:00 | 2021-10-17T05:00:06.713857+00:00 | 890 | false | The problem is another version of subset sum. Here, we need to calculate OR of every non empty subset instead of sum.\n\n*To generate all possible subset, each step we need to make two decisons. We will take this number to result or leave it. At the end, if at least one number is taken ( no empty subset ), we will chec... | 6 | 1 | ['Backtracking', 'C'] | 1 |
count-number-of-maximum-bitwise-or-subsets | [Python3] Dynamic Programming + Bit Manipulation + Greedy - Detailed Solution | python3-dynamic-programming-bit-manipula-xzyv | Intuition\n Describe your first thoughts on how to solve this problem. \n- the more numbers added into current number by or operation, the more chance the curre | dolong2110 | NORMAL | 2024-10-18T19:39:36.861251+00:00 | 2024-10-18T19:39:36.861285+00:00 | 36 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n- the more numbers added into current number by `or` operation, the more chance the current number incresase. Thus, the maximum or of `nums` - `max_or` is just the `or` operation in all elements in `nums`\n- After knowing the `max_or` in ... | 5 | 0 | ['Array', 'Dynamic Programming', 'Backtracking', 'Bit Manipulation', 'Python3'] | 0 |
count-number-of-maximum-bitwise-or-subsets | Count Maximum OR Subsets Using Bit Masking | Java | C++ | Video Solution | count-maximum-or-subsets-using-bit-maski-2b8f | Intuition, approach, and complexity dicussed in video solution in detail\nhttps://youtu.be/wO_4VjvrqQQ\n# Code\nJava []\nclass Solution {\n public int countM | Lazy_Potato_ | NORMAL | 2024-10-18T12:42:18.355684+00:00 | 2024-10-18T12:42:18.355709+00:00 | 749 | false | # Intuition, approach, and complexity dicussed in video solution in detail\nhttps://youtu.be/wO_4VjvrqQQ\n# Code\n``` Java []\nclass Solution {\n public int countMaxOrSubsets(int[] nums) {\n int size = nums.length;\n int maxOR = 0, maxORCnt = 0;\n int totalSS = (1 << size) - 1;\n for(int ... | 5 | 0 | ['Array', 'Bit Manipulation', 'Enumeration', 'C++', 'Java'] | 1 |
count-number-of-maximum-bitwise-or-subsets | BackTracking Approach | 99.43% Beats | Beginner friendly | backtracking-approach-9943-beats-beginne-dc2a | Intuition\nThe problem is about finding subsets that produce the maximum possible bitwise OR. First, compute the maximum OR by applying the OR operation across | nagastu02 | NORMAL | 2024-10-18T04:10:35.230435+00:00 | 2024-10-18T04:10:35.230464+00:00 | 902 | false | # Intuition\nThe problem is about finding subsets that produce the maximum possible bitwise OR. First, compute the maximum OR by applying the OR operation across all elements of the array. After that, use a backtracking approach to generate all possible subsets and count how many produce this maximum OR. We can also op... | 5 | 0 | ['Array', 'Backtracking', 'Bit Manipulation', 'Enumeration', 'Python', 'C++', 'Java', 'JavaScript'] | 4 |
count-number-of-maximum-bitwise-or-subsets | Straight Forward approach💯🫡 | easy to understand✅✅✅ | C++👑 | straight-forward-approach-easy-to-unders-paxi | \n\n# Code\ncpp []\nclass Solution {\npublic:\n int countMaxOrSubsets(vector<int>& nums) {\n int n = nums.size();\n int m = 0, c = 0;\n\n | ritik6g | NORMAL | 2024-10-18T00:22:27.388217+00:00 | 2024-10-18T00:22:27.388242+00:00 | 1,303 | false | \n\n# Code\n```cpp []\nclass Solution {\npublic:\n int countMaxOrSubsets(vector<int>& nums) {\n int n = nums.size();\n int m = 0, c = 0;\n\n for (int x : nums) {\n m |= x;\n }\n\n int t = 1 << n;\n for (int mask = 1; mask < t; ++mask) {\n int o = 0;\n ... | 5 | 0 | ['C++'] | 2 |
count-number-of-maximum-bitwise-or-subsets | C++ || Recursion | c-recursion-by-aditya_pratap1-8urp | The maximum OR value possible for any subset of an array is the OR of all values in the array!\nAfter calculating the maximum OR possible, we\'ll find OR of all | aditya_pratap1 | NORMAL | 2022-02-24T05:47:39.793826+00:00 | 2022-04-19T11:23:18.588856+00:00 | 587 | false | The **maximum OR value possible for any subset of an array is the OR of all values in the array!**\nAfter calculating the maximum OR possible, we\'ll find OR of all subsets & check if it is equal to maximum OR :\n```\nint recur(vector<int>&nums,int idx,int currOr,int maxOr){\n if(idx < 0){\n return cu... | 5 | 0 | ['Recursion', 'C'] | 2 |
count-number-of-maximum-bitwise-or-subsets | Python3 - bitmask | dp | python3-bitmask-dp-by-zhuzhengyuan824-r13l | See more similar bitmask dp type questions here: https://leetcode.com/discuss/general-discussion/1125779/Dynamic-programming-on-subsets-with-examples-explained | zhuzhengyuan824 | NORMAL | 2021-10-17T07:14:49.054509+00:00 | 2021-10-17T07:14:49.054549+00:00 | 386 | false | See more similar `bitmask dp` type questions here: https://leetcode.com/discuss/general-discussion/1125779/Dynamic-programming-on-subsets-with-examples-explained\n\n``` py\nclass Solution:\n def countMaxOrSubsets(self, nums: List[int]) -> int:\n N = len(nums)\n dp = [-1] * (1<<N)\n dp[0] = 0\n ... | 5 | 0 | ['Bitmask', 'Python', 'Python3'] | 1 |
count-number-of-maximum-bitwise-or-subsets | C++ || SIMPLE RECURSION || BEGINNER FRIENDLY | c-simple-recursion-beginner-friendly-by-5ifmy | \nclass Solution {\npublic:\n int count=0;\n int countMaxOrSubsets(vector<int>& nums) {\n long long bitOr=nums[0];\n for(int i=1;i<nums.size | VineetKumar2023 | NORMAL | 2021-10-17T04:18:15.467330+00:00 | 2021-10-17T04:18:15.467367+00:00 | 272 | false | ```\nclass Solution {\npublic:\n int count=0;\n int countMaxOrSubsets(vector<int>& nums) {\n long long bitOr=nums[0];\n for(int i=1;i<nums.size();i++)\n bitOr|=nums[i];\n subsets(nums,0,0,bitOr);\n return count;\n }\n void subsets(vector<int>& nums,int i,int now,int bi... | 5 | 0 | [] | 1 |
count-number-of-maximum-bitwise-or-subsets | Simple Search | simple-search-by-votrubac-q3vv | We can add memoisation, but it is easy to verify that we do not need it. The runtime is just a few ms already.\n\nC++\ncpp\nint dfs(vector<int>& n, int i, int c | votrubac | NORMAL | 2021-10-17T04:01:40.909348+00:00 | 2021-10-17T05:58:08.791162+00:00 | 227 | false | We can add memoisation, but it is easy to verify that we do not need it. The runtime is just a few ms already.\n\n**C++**\n```cpp\nint dfs(vector<int>& n, int i, int cur_or, int max_or) {\n if (i >= n.size())\n return max_or == cur_or;\n else\n return dfs(n, i + 1, cur_or, max_or) + dfs(n, i + 1, cu... | 5 | 4 | [] | 1 |
count-number-of-maximum-bitwise-or-subsets | Simple py,JAVA code using recursion!! | simple-pyjava-code-using-recursion-by-ar-079a | Similar question\n\n- Try solving this question : 78. Subsets\n- SOLUTION: "Click here for solution"\n\n---\n\n\n# Approach:Recursion\n Describe your approach t | arjunprabhakar1910 | NORMAL | 2024-10-18T19:23:00.267386+00:00 | 2024-10-18T19:28:10.143038+00:00 | 74 | false | # Similar question\n\n- Try solving this question : [78. Subsets](https://leetcode.com/problems/subsets/description/)\n- SOLUTION: ["Click here for solution"](https://leetcode.com/problems/subsets/solutions/5932957/simple-py-java-code-using-recursion)\n\n---\n\n\n# Approach:Recursion\n<!-- Describe your approach to sol... | 4 | 0 | ['Array', 'Recursion', 'Java', 'Python3'] | 0 |
count-number-of-maximum-bitwise-or-subsets | Easy Solve.........🔥🔥🔥🔥🔥 | easy-solve-by-pritambanik-skr6 | 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 | PritamBanik | NORMAL | 2024-10-18T18:25:02.311006+00:00 | 2024-10-18T18:25:02.311038+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: 100%\u2705\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. ... | 4 | 0 | ['Array', 'Backtracking', 'Bit Manipulation', 'C', 'Enumeration'] | 0 |
count-number-of-maximum-bitwise-or-subsets | C++ Solution || Simple Recursion || Detailed Explanation | c-solution-simple-recursion-detailed-exp-mjvj | Intuition\nThe problem requires us to count how many subsets of the given array have the maximum possible bitwise OR value. The idea is to:\n1. Calculate the ma | Rohit_Raj01 | NORMAL | 2024-10-18T06:22:08.848491+00:00 | 2024-10-18T06:22:08.848522+00:00 | 368 | false | # Intuition\nThe problem requires us to count how many subsets of the given array have the maximum possible bitwise OR value. The idea is to:\n1. **Calculate the maximum possible OR** value by OR-ing all elements of the array.\n2. **Recursively explore all subsets**, keeping track of the OR value of the current subset.... | 4 | 0 | ['Array', 'Backtracking', 'Bit Manipulation', 'C++'] | 1 |
count-number-of-maximum-bitwise-or-subsets | Simple Approach | 🌟 Beats 100.00% 🚀 || Step-by-Step Breakdown 💯🔥 | simple-approach-beats-10000-step-by-step-lyuh | \n\n# Intuition\nThe goal of the code is to compute how many subsets of the list nums can produce the maximum possible bitwise OR.\n# Approach\n\n1. Initialize: | hemanta8338 | NORMAL | 2024-10-18T05:52:38.962646+00:00 | 2024-10-18T05:52:38.962686+00:00 | 311 | false | \n\n# Intuition\nThe goal of the code is to compute how many subsets of the list nums can produce the maximum possible bitwise OR.\n# Approach\n\n1. **Initialize**:\n - Initialize `dp` as a hash map, star... | 4 | 0 | ['Array', 'Dynamic Programming', 'Bit Manipulation', 'Bitmask', 'Python', 'Python3'] | 0 |
count-number-of-maximum-bitwise-or-subsets | [Golang] Backtracking | Simple Solution | golang-backtracking-simple-solution-by-s-i2en | Approach\n- The maximum OR is the OR of the array. We can find it by traversing the array and performing OR operation for every number in it. That value will be | suoncha | NORMAL | 2024-10-18T03:58:11.411120+00:00 | 2024-10-18T03:58:11.411158+00:00 | 51 | false | # Approach\n- The maximum OR is the OR of the array. We can find it by traversing the array and performing OR operation for every number in it. That value will be saved to `target`\n- Once we found it, perform backtrack starting from the first index to generate all possible subsets. Instead of tracking the entire subse... | 4 | 0 | ['Go'] | 0 |
count-number-of-maximum-bitwise-or-subsets | C++ ✅ | Bitmasking 🚀 | c-bitmasking-by-jatin1510-ylr9 | Intuition\n Describe your first thoughts on how to solve this problem. \nThe key idea here is to recognize that the bitwise OR operation tends to grow the more | jatin1510 | NORMAL | 2024-10-18T03:30:10.365339+00:00 | 2024-10-18T03:30:10.365374+00:00 | 757 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe key idea here is to recognize that the bitwise OR operation tends to grow the more elements you include in the subset, since the OR operation accumulates set bits from all the elements. Our goal is to find the maximum bitwise OR we ca... | 4 | 0 | ['Bit Manipulation', 'Enumeration', 'C++'] | 0 |
count-number-of-maximum-bitwise-or-subsets | 💥💥Easy 3 line solution Beats 80%✅✅O(2^n) | easy-3-line-solution-beats-80o2n-by-shad-hnjq | Intuition\nTrying all Combinations (same as combination sum question)\n# Approach\nTrying all Combinations\n\n\u26A1To get all the possible combinations\uD83D\u | shady__ | NORMAL | 2024-10-18T00:43:12.960473+00:00 | 2024-10-18T00:43:12.960505+00:00 | 405 | false | # Intuition\nTrying all Combinations (same as combination sum question)\n# Approach\nTrying all Combinations\n\n\u26A1To get all the possible combinations\uD83D\uDFE2\n\u26A1At each element we got two choises take that element or leave it\n\u26A1The base Case is reaching the end of the array\n\n\n# Complexity\n- Time c... | 4 | 0 | ['Backtracking', 'C++'] | 3 |
count-number-of-maximum-bitwise-or-subsets | BRUTE FORCE 2^n || C++ | brute-force-2n-c-by-ganeshkumawat8740-6z99 | Code\n\nclass Solution {\npublic:\n void solve(int i,int x,int k,vector<int> &v,int &ans){\n // if(x==k)ans++;\n if(i>=v.size()){ans += (x==k); | ganeshkumawat8740 | NORMAL | 2023-06-13T03:13:13.654943+00:00 | 2023-06-13T03:13:13.654963+00:00 | 486 | false | # Code\n```\nclass Solution {\npublic:\n void solve(int i,int x,int k,vector<int> &v,int &ans){\n // if(x==k)ans++;\n if(i>=v.size()){ans += (x==k);return;}\n solve(i+1,x,k|v[i],v,ans);\n solve(i+1,x,k,v,ans);\n }\n int countMaxOrSubsets(vector<int>& nums) {\n int x = 0;\n ... | 4 | 0 | ['Array', 'Backtracking', 'Bit Manipulation', 'C++'] | 0 |
count-number-of-maximum-bitwise-or-subsets | Simple Solution in Java | simple-solution-in-java-by-s34-5h15 | Hints\n- The maximum bitwise-OR is the bitwise-OR of the whole array (max)\n- Use bitwise operation to find all the possible subset of given array\n- If max==th | s34 | NORMAL | 2022-02-13T12:29:49.396565+00:00 | 2022-02-13T12:29:49.396596+00:00 | 162 | false | **Hints**\n- The maximum bitwise-OR is the bitwise-OR of the whole array (max)\n- Use bitwise operation to find all the possible subset of given array\n- If max==the OR of subset, count++\n```\nclass Solution {\n public int countMaxOrSubsets(int[] nums) {\n int max=0,tmp=0,count=0;\n //The maximum bitw... | 4 | 0 | [] | 0 |
count-number-of-maximum-bitwise-or-subsets | [C++] Recursive DP solution | c-recursive-dp-solution-by-marcos_999-jq4a | This Problem is similar to number of subset with given sum.\nSo the basic approch is that pick one by one element and calculate the OR and check if it equal to | marcos_999 | NORMAL | 2021-10-21T05:54:47.768322+00:00 | 2021-10-21T05:54:47.768368+00:00 | 407 | false | This Problem is similar to number of subset with given sum.\nSo the basic approch is that pick one by one element and calculate the OR and check if it equal to resultant OR.\nFirst try to write recursive code and then do the memorization to reduce the time complexity.\n\n``` \nclass Solution {\npublic:\n vector<vect... | 4 | 0 | ['Dynamic Programming'] | 1 |
count-number-of-maximum-bitwise-or-subsets | Java DFS with pruning beats 100% | java-dfs-with-pruning-beats-100-by-jianw-lsy0 | A simple DFS solution with prunig. Whenever preSum equals sum, there\'s no need to do further recursion calls as all remaining combinations will satisfy the con | jianwu | NORMAL | 2021-10-20T07:15:51.551214+00:00 | 2021-10-20T07:15:51.551258+00:00 | 303 | false | A simple DFS solution with prunig. Whenever `preSum` equals `sum`, there\'s no need to do further recursion calls as all remaining combinations will satisfy the condition. So we can simply add `2^remainCount` will do.\n\n```java\nclass Solution {\n int result;\n int sum;\n public int countMaxOrSubsets(int[] nums) {\... | 4 | 0 | [] | 0 |
count-number-of-maximum-bitwise-or-subsets | C++ | Bitmasking | c-bitmasking-by-mohit_ahirwar-hyqn | \nclass Solution {\npublic:\n int countMaxOrSubsets(vector<int>& nums) {\n int n = nums.size(),ans=0,m = nums[0];\n for(int i=1;i<n;i++) m |= n | Mohit_Ahirwar | NORMAL | 2021-10-17T04:51:04.116001+00:00 | 2021-10-17T04:51:04.116037+00:00 | 521 | false | ```\nclass Solution {\npublic:\n int countMaxOrSubsets(vector<int>& nums) {\n int n = nums.size(),ans=0,m = nums[0];\n for(int i=1;i<n;i++) m |= nums[i]; // Max-OR : OR of all elements\n int k = 1 << n;\n for(int i=0;i<k;i++){\n int j = i,c=0,l=0;\n while(j > 0){\n ... | 4 | 0 | [] | 1 |
count-number-of-maximum-bitwise-or-subsets | [Java] Math + Modified Backtracking 3ms beat 100% after sort Array (with detailed explanation) | java-math-modified-backtracking-3ms-beat-7wfi | Find the maxOR num \n2. Sort array for more efficient backtracking latter\n3. Backtrack the array from the biggest number to smallest one(because the maxOR must | keyi | NORMAL | 2021-10-17T04:43:34.874804+00:00 | 2021-10-17T07:46:28.793162+00:00 | 620 | false | 1. Find the maxOR num \n2. Sort array for more efficient backtracking latter\n3. Backtrack the array from the biggest number to smallest one(because the maxOR must be from the biggest one)\n4. Say the sorted array is `[1,2,3,5]` and we start from the last element 5. when it goes to 2, the `existingOR` is already the ma... | 4 | 0 | ['Math', 'Backtracking', 'Java'] | 1 |
count-number-of-maximum-bitwise-or-subsets | Java || Simple || Easy to Understand | java-simple-easy-to-understand-by-kdhaka-eylo | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | kdhakal | NORMAL | 2025-02-27T16:17:14.237323+00:00 | 2025-02-27T16:17:14.237323+00:00 | 28 | 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
`... | 3 | 0 | ['Java'] | 0 |
count-number-of-maximum-bitwise-or-subsets | Simple C++ solution | Backtracking | simple-c-solution-backtracking-by-saurab-nwza | Intuition\nWe will generate all te subsets using backtracking and check if their bitwise or is the maximum and return the count.\n\n# Approach\n1. Compute the m | saurabhdamle11 | NORMAL | 2024-10-18T14:17:02.817384+00:00 | 2024-10-18T14:17:02.817416+00:00 | 198 | false | # Intuition\nWe will generate all te subsets using backtracking and check if their bitwise or is the maximum and return the count.\n\n# Approach\n1. Compute the maximum bitwise or of all the elements possible.\n2. Generate all possible subsets using recursion and for every subset, check if the xor is equal to maximum p... | 3 | 0 | ['Array', 'Backtracking', 'Bit Manipulation', 'Enumeration', 'C++', 'Java'] | 2 |
count-number-of-maximum-bitwise-or-subsets | Beats 100% || Java, Python, C++ detailed solution | beats-100-java-python-c-detailed-solutio-anz0 | Intuition\nThe goal of this problem is to find the number of subsets whose bitwise OR equals the maximum possible bitwise OR of all elements in the array. The b | yashringe | NORMAL | 2024-10-18T10:26:04.099026+00:00 | 2024-10-18T10:26:04.099055+00:00 | 78 | false | # Intuition\nThe goal of this problem is to find the number of subsets whose bitwise OR equals the maximum possible bitwise OR of all elements in the array. The brute-force way to solve this problem would be to generate all possible subsets and compute their OR values. However, this can be optimized by using recursion ... | 3 | 0 | ['C++', 'Java', 'Python3'] | 0 |
count-number-of-maximum-bitwise-or-subsets | Easy Solution | JavaScript | C++ | Python | easy-solution-javascript-c-python-by-nur-a8b8 | Intuition\n- We enumerate all possible subsets\n- The maximum bitwise-OR is the bitwise-OR of the whole array.\n# Approach\n\n\n### 1. Calculate Maximum OR (max | Nurliaidin | NORMAL | 2024-10-18T08:45:27.219623+00:00 | 2024-10-18T08:45:27.219657+00:00 | 316 | false | # Intuition\n- We enumerate all possible subsets\n- The maximum bitwise-OR is the bitwise-OR of the whole array.\n# Approach\n\n\n### 1. **Calculate Maximum OR (`maxBit`):**\n - First, calculate the maximum possible OR value (`maxBit`) by taking the bitwise OR of all the elements in the array. This value will be the ... | 3 | 0 | ['Array', 'Backtracking', 'Bit Manipulation', 'Enumeration', 'C++', 'Python3', 'JavaScript'] | 1 |
count-number-of-maximum-bitwise-or-subsets | Java Clean Solution | java-clean-solution-by-shree_govind_jee-nofi | 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-10-18T04:56:48.668370+00:00 | 2024-10-18T04:56:48.668403+00:00 | 508 | 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```java []\nclass Solution {\n List<Integer> or_list = new ArrayList<>();\n\n private void helper(int[] nums, int sum, i... | 3 | 0 | ['Array', 'Backtracking', 'Bit Manipulation', 'Enumeration', 'Java'] | 0 |
count-number-of-maximum-bitwise-or-subsets | C# Solution for Count Number of Maximum Bitwise - OR Subsets Problem | c-solution-for-count-number-of-maximum-b-at79 | Intuition\n Describe your first thoughts on how to solve this problem. \nThe problem is about finding subsets whose bitwise OR equals the maximum possible OR th | Aman_Raj_Sinha | NORMAL | 2024-10-18T03:14:15.868306+00:00 | 2024-10-18T03:14:15.868347+00:00 | 197 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe problem is about finding subsets whose bitwise OR equals the maximum possible OR that can be achieved from the array. Since there are 2^n subsets for an array of length n, and the OR operation accumulates values as elements are added ... | 3 | 0 | ['C#'] | 0 |
count-number-of-maximum-bitwise-or-subsets | Easy solution, using backtracking. Daily Question 18/10/24 | easy-solution-using-backtracking-daily-q-7rw1 | Intuition\nThe thought is to compute all the subsets and calculate their ors, store all the ors in a list and return the count of max of that list.\n\n# Approac | LalithSrinandan | NORMAL | 2024-10-18T03:12:57.241591+00:00 | 2024-10-18T03:12:57.241622+00:00 | 81 | false | # Intuition\nThe thought is to compute all the subsets and calculate their ors, store all the ors in a list and return the count of max of that list.\n\n# Approach\nStep1: Use backtracking to compute all the subsets.\nStep2: Or the elements of the subset.\nStep3: Store all the ors in a list.\nStep4: Return the count of... | 3 | 0 | ['Java'] | 0 |
count-number-of-maximum-bitwise-or-subsets | Fastest code with Step-by-Step Breakdown 💯🔥 | fastest-code-with-step-by-step-breakdown-kaaw | Intuition\n Describe your first thoughts on how to solve this problem. \nThe problem revolves around finding how many subsets of a given array have a bitwise OR | uk07 | NORMAL | 2024-10-18T02:33:47.814707+00:00 | 2024-10-18T02:33:47.814762+00:00 | 568 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe problem revolves around finding how many subsets of a given array have a bitwise OR that equals the maximum OR possible for the entire array. The key insight is that we need to determine the maximum OR value of all elements combined a... | 3 | 1 | ['Array', 'Bit Manipulation', 'Enumeration', 'Python', 'C++', 'Java', 'Go', 'Python3', 'Rust', 'JavaScript'] | 1 |
count-number-of-maximum-bitwise-or-subsets | Got the job done with hashmap(defaultdict) | 100% efficiency with proof | Python solution | got-the-job-done-with-hashmapdefaultdict-n0nc | \n\n\n# Code\nPython []\nclass Solution(object):\n def countMaxOrSubsets(self, nums):\n hashmap = defaultdict(int)\n for i in nums:\n | Hamza_the_codar_786 | NORMAL | 2024-07-10T07:50:54.161993+00:00 | 2024-07-10T07:50:54.162026+00:00 | 34 | false | \n\n\n# Code\n``` Python []\nclass Solution(object):\n def countMaxOrSubsets(self, nums):\n hashmap = defaultdict(int)\n for i in nums:\n temp = dict(hashmap)\n for j ... | 3 | 0 | ['Array', 'Backtracking', 'Bit Manipulation', 'Python'] | 0 |
count-number-of-maximum-bitwise-or-subsets | BRUTER-FORCE || 2^n SOLUTION || C++ || EASY TO UNDERSTAND | bruter-force-2n-solution-c-easy-to-under-b3u6 | \nclass Solution {\npublic:\n int x = 0;\n void solve(int s,int k,int &ans,vector<int> &nums){\n if(s>=nums.size()){\n if(k==x)\n | yash___sharma_ | NORMAL | 2023-03-28T12:57:43.296193+00:00 | 2023-03-28T12:57:43.296240+00:00 | 865 | false | ````\nclass Solution {\npublic:\n int x = 0;\n void solve(int s,int k,int &ans,vector<int> &nums){\n if(s>=nums.size()){\n if(k==x)\n ans++;\n return;\n }\n solve(s+1,k|nums[s],ans,nums);\n solve(s+1,k,ans,nums);\n }\n int countMaxOrSubsets(ve... | 3 | 0 | ['Recursion', 'C', 'Bitmask', 'C++'] | 0 |
count-number-of-maximum-bitwise-or-subsets | C++ | Backtracking | c-backtracking-by-sosuke23-ph4p | Code\n\nclass Solution {\npublic:\n int countMaxOrSubsets(vector<int>& nums) {\n int reach=0,res=0;\n for(auto x:nums){\n reach|=x;\ | Sosuke23 | NORMAL | 2023-03-17T10:43:10.446058+00:00 | 2023-03-17T10:43:10.446093+00:00 | 302 | false | # Code\n```\nclass Solution {\npublic:\n int countMaxOrSubsets(vector<int>& nums) {\n int reach=0,res=0;\n for(auto x:nums){\n reach|=x;\n }\n auto Solve=[&](auto Solve,int ind,int val){\n if(val>67108864){\n return ;\n }\n if(val... | 3 | 0 | ['Backtracking', 'C++'] | 0 |
count-number-of-maximum-bitwise-or-subsets | C++ | 2 solution | Backtracking + DP Soln | c-2-solution-backtracking-dp-soln-by-ita-kgq9 | Backtracking Soln\n\n\tint res = 0;\n void back(vector<int>nums, int a, int idx, int curr) {\n if(curr==a) res+=1;\n for(int i=idx; i<nums.size | itachi_sks | NORMAL | 2022-01-19T05:38:09.626944+00:00 | 2022-01-20T09:39:03.626655+00:00 | 261 | false | # Backtracking Soln\n```\n\tint res = 0;\n void back(vector<int>nums, int a, int idx, int curr) {\n if(curr==a) res+=1;\n for(int i=idx; i<nums.size(); i++) {\n back(nums, a, i+1, curr|nums[i]);\n }\n }\n int countMaxOrSubsets(vector<int>& nums) {\n long long a = nums[0];... | 3 | 0 | ['Math', 'Backtracking', 'C'] | 0 |
count-number-of-maximum-bitwise-or-subsets | Python3 Solution | python3-solution-by-satyam2001-40gs | \nclass Solution:\n def countMaxOrSubsets(self, nums: List[int]) -> int:\n \n def dfs(i,val):\n if maxBit == val : return 1<<(len(nu | satyam2001 | NORMAL | 2021-11-13T15:04:57.860102+00:00 | 2021-11-13T15:04:57.860140+00:00 | 631 | false | ```\nclass Solution:\n def countMaxOrSubsets(self, nums: List[int]) -> int:\n \n def dfs(i,val):\n if maxBit == val : return 1<<(len(nums)-i)\n if i == len(nums): return 0\n return dfs(i+1,val|nums[i]) + dfs(i+1,val)\n maxBit = 0\n for i in nums: maxBit |=... | 3 | 0 | ['Backtracking', 'Python', 'Python3'] | 0 |
count-number-of-maximum-bitwise-or-subsets | C++ Simple and Short Solution, No Recursion, Faster than 100% | c-simple-and-short-solution-no-recursion-p08u | Very similar to https://leetcode.com/problems/subsets/discuss/1333022/C%2B%2B-Simple-and-Short-Solution-No-Recursion-0-ms-Faster-than-100\n\nclass Solution {\np | yehudisk | NORMAL | 2021-10-17T13:15:06.339306+00:00 | 2021-10-17T13:15:06.339338+00:00 | 141 | false | Very similar to https://leetcode.com/problems/subsets/discuss/1333022/C%2B%2B-Simple-and-Short-Solution-No-Recursion-0-ms-Faster-than-100\n```\nclass Solution {\npublic:\n int countMaxOrSubsets(vector<int>& nums) {\n int res = 0, mx_or = 0, curr, sz;\n vector<int> ors = {0};\n \n for (aut... | 3 | 1 | ['C', 'Iterator'] | 0 |
count-number-of-maximum-bitwise-or-subsets | C++ Failed Approach + Working One | c-failed-approach-working-one-by-abhi_ve-n86p | Code is correct but time complexity is high so below approach failed at last test case :(\nHere we are generating every possible sub array and doing its OR in b | abhi_vee | NORMAL | 2021-10-17T04:27:59.418257+00:00 | 2021-10-17T04:29:43.818874+00:00 | 292 | false | Code is correct but time complexity is high so below approach failed at last test case :(\nHere we are generating every possible sub array and doing its OR in base condition.\n```\nclass Solution {\npublic:\n int res=0, ans=INT_MIN;\n void solve(vector<int> input, vector<int> output)\n {\n if(input.size... | 3 | 0 | ['Backtracking', 'C', 'C++'] | 1 |
count-number-of-maximum-bitwise-or-subsets | C++ bitmask solution. brute-force. | c-bitmask-solution-brute-force-by-chejia-j50v | \n\nclass Solution {\npublic:\n int countMaxOrSubsets(vector<int>& nums) {\n int n = nums.size();\n int all = 1 << n;\n int ans = 0;\n | chejianchao | NORMAL | 2021-10-17T04:00:40.696357+00:00 | 2021-10-17T04:00:40.696395+00:00 | 173 | false | \n```\nclass Solution {\npublic:\n int countMaxOrSubsets(vector<int>& nums) {\n int n = nums.size();\n int all = 1 << n;\n int ans = 0;\n int mx = 0;\n for(int i = 1; i < all; i++) {\n int val = 0;\n for(int j = 0; j < n; j++) {\n if((1 << j) & ... | 3 | 2 | [] | 0 |
count-number-of-maximum-bitwise-or-subsets | 🔥Lollipop BEATS 💯 % 🎯 |✨SUPER EASY BEGINNERS 👏 | lollipop-beats-super-easy-beginners-by-c-v5ue | \n\n\n---\n\n## Intuition\nThe problem is about finding how many subsets of a list of integers have a bitwise OR equal to the maximum possible bitwise OR of the | CodeWithSparsh | NORMAL | 2024-10-21T16:03:07.802941+00:00 | 2024-10-21T16:10:18.742230+00:00 | 19 | false | \n\n\n---\n\n## Intuition\nThe problem is about finding how many subsets of a list of integers have a bitwise OR equal to the maximum possible bitwise OR of the entire list. The maximum bitwise OR is achiev... | 2 | 0 | ['Bit Manipulation', 'Recursion', 'C', 'C++', 'Java', 'Go', 'Python3', 'JavaScript', 'Dart'] | 1 |
count-number-of-maximum-bitwise-or-subsets | 🚀Completed in 14ms: Beats 100%!🚀 | completed-in-14ms-beats-100-by-dddurnov-94qx | \n\n\n\n# Complexity\n- Time complexity: O(2^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 | dddurnov | NORMAL | 2024-10-18T16:21:15.352476+00:00 | 2024-10-18T16:21:15.352526+00:00 | 32 | false | \n\n\n\n# Complexity\n- Time complexity: $$O(2^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 ... | 2 | 0 | ['Array', 'Backtracking', 'Bit Manipulation', 'Enumeration', 'TypeScript', 'JavaScript'] | 0 |
count-number-of-maximum-bitwise-or-subsets | Beats 100% || Clean code using Counter in python | beats-100-clean-code-using-counter-in-py-8ynd | 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 | anand_shukla1312 | NORMAL | 2024-10-18T13:45:45.559174+00:00 | 2024-10-18T13:45:45.559209+00:00 | 27 | 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)$$ --... | 2 | 0 | ['Python3'] | 0 |
count-number-of-maximum-bitwise-or-subsets | easy take not take solution | easy-take-not-take-solution-by-batch89-mav6 | 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 | batch89 | NORMAL | 2024-10-18T13:27:52.906099+00:00 | 2024-10-18T13:27:52.906136+00:00 | 13 | 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)$$ --... | 2 | 0 | ['C++'] | 0 |
count-number-of-maximum-bitwise-or-subsets | Simple & Easy Solution with step by step explanation | simple-easy-solution-with-step-by-step-e-bb1z | Approach\n- Step 1: Find the maximum possible OR of the entire array. This value is the OR of all elements combined, as it represents the upper bound of any sub | yash_visavadia | NORMAL | 2024-10-18T13:15:26.038452+00:00 | 2024-10-18T13:15:26.038477+00:00 | 10 | false | # Approach\n- **Step 1:** Find the maximum possible OR of the entire array. This value is the OR of all elements combined, as it represents the upper bound of any subset OR.\n\n- **Step 2:** Iterate through all possible subsets of the array (using itertools.combinations) and calculate the OR of each subset. Count how m... | 2 | 0 | ['Python3'] | 0 |
count-number-of-maximum-bitwise-or-subsets | [Swift] 1-liner, combinations(ofCount:) | swift-1-liner-combinationsofcount-by-iam-syhj | \n\n# Code\nswift []\nimport Algorithms\n\nclass Solution {\n func countMaxOrSubsets(_ nums: [Int]) -> Int {\n nums\n .combinations(ofCount: 1. | iamhands0me | NORMAL | 2024-10-18T11:13:26.974883+00:00 | 2024-10-18T11:13:56.219218+00:00 | 26 | false | \n\n# Code\n```swift []\nimport Algorithms\n\nclass Solution {\n func countMaxOrSubsets(_ nums: [Int]) -> Int {\n nums\n .combinations(ofCount: 1...)\n .map { $0.reduce(into: 0) { $0 = $0 | $1 } }\n .reduce(into: [:]) { $0[$1, default: 0] += 1 }\n .max { $0.key < $1.key }?.value ??... | 2 | 0 | ['Swift'] | 1 |
count-number-of-maximum-bitwise-or-subsets | Beginner friendly- two approach ✅ ✅ | beginner-friendly-two-approach-by-shasha-uo3s | Intuition\nThe goal is to find the maximum possible bitwise OR of any subset of the array nums and count how many subsets achieve this maximum OR.\n\n# Approach | shashankgpt07 | NORMAL | 2024-10-18T09:05:18.325449+00:00 | 2024-10-18T09:05:18.325469+00:00 | 80 | false | # Intuition\nThe goal is to find the maximum possible bitwise OR of any subset of the array nums and count how many subsets achieve this maximum OR.\n\n# Approach\n1. **Calculate Maximum OR**: The maximum OR is achieved by ORing all elements together. This gives the maximum OR any subset can achieve.\n\n2. **Count Subs... | 2 | 0 | ['Array', 'Bit Manipulation', 'Recursion', 'Enumeration', 'C++'] | 0 |
count-number-of-maximum-bitwise-or-subsets | 100% beat | Simple Approach | Recursion | 100-beat-simple-approach-recursion-by-ay-7ujp | 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 | Ayush6944 | NORMAL | 2024-10-18T07:01:24.416923+00:00 | 2024-10-18T07:01:24.416952+00:00 | 173 | 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)$$ --... | 2 | 0 | ['Array', 'Backtracking', 'Bit Manipulation', 'Python3', 'JavaScript'] | 0 |
count-number-of-maximum-bitwise-or-subsets | Take or Not Take ✅ || [C++] 🚀 || Easy step by step 💯 | take-or-not-take-c-easy-step-by-step-by-9e8qn | \nclass Solution {\nint ans = 0;\nprivate:\n int helpXOR(vector<int>& temp)\n {\n if (temp.empty()) return 0;\n int count = temp[0];\n | RIOLOG | NORMAL | 2024-10-18T05:29:33.845694+00:00 | 2024-10-18T05:29:33.845714+00:00 | 88 | false | ```\nclass Solution {\nint ans = 0;\nprivate:\n int helpXOR(vector<int>& temp)\n {\n if (temp.empty()) return 0;\n int count = temp[0];\n for (int i=1;i<temp.size();i++) count |= temp[i];\n return count;\n }\n \n void helpmeRec(int ind, vector<int>& nums, int target , v... | 2 | 0 | ['Backtracking', 'Recursion', 'C++'] | 0 |
count-number-of-maximum-bitwise-or-subsets | JAVA BACKTRACKING SOLUTION || KHANDANI BACKTRACKING TEMPLATE | java-backtracking-solution-khandani-back-4i0h | Intuition\n\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- Tim | abhinavsinghnegi | NORMAL | 2024-10-18T05:15:27.464083+00:00 | 2024-10-18T05:15:27.464108+00:00 | 219 | false | # Intuition\n\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 compl... | 2 | 0 | ['Java'] | 0 |
count-number-of-maximum-bitwise-or-subsets | Backtracking solution, very easy to understand | backtracking-solution-very-easy-to-under-293k | Intuition\n Describe your first thoughts on how to solve this problem. \nSince the max length of the array is just 16, we use backtracking to check all possible | aiqqia | NORMAL | 2024-10-18T04:19:06.626134+00:00 | 2024-10-18T04:19:06.626181+00:00 | 39 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nSince the max length of the array is just 16, we use backtracking to check all possible subsets of this array and if any of the subset\'s OR is the same as the max OR, we add it to the answer. \n\n# Approach\n<!-- Describe your approach t... | 2 | 0 | ['Java'] | 1 |
count-number-of-maximum-bitwise-or-subsets | #beats 100% #simple recursive solution #Include/Not-Include Pattern | beats-100-simple-recursive-solution-incl-u2zt | Intuition\nThe task requires counting the number of subsets whose bitwise OR value equals the maximum possible bitwise OR that can be obtained from all elements | Adarsh_Gupta_0601 | NORMAL | 2024-10-18T03:22:02.292892+00:00 | 2024-10-18T03:22:02.292924+00:00 | 35 | false | # Intuition\nThe task requires counting the number of subsets whose bitwise OR value equals the maximum possible bitwise OR that can be obtained from all elements in the array. By recursively exploring all possible subsets, we can find how many subsets meet this condition.\n\n# Approach\n1. Calculate Maximum Bitwise OR... | 2 | 0 | ['Array', 'Backtracking', 'Bit Manipulation', 'Recursion', 'C++'] | 2 |
count-number-of-maximum-bitwise-or-subsets | Java Solution for Count Number of Maximum Bitwise - OR Subsets Problem | java-solution-for-count-number-of-maximu-wuob | Intuition\n Describe your first thoughts on how to solve this problem. \nThe goal is to find the maximum possible bitwise OR of a subset of the given array and | Aman_Raj_Sinha | NORMAL | 2024-10-18T03:08:52.881950+00:00 | 2024-10-18T03:08:52.881985+00:00 | 247 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe goal is to find the maximum possible bitwise OR of a subset of the given array and count how many different non-empty subsets can achieve this maximum OR value. Since the bitwise OR operation accumulates values as more elements are ad... | 2 | 0 | ['Java'] | 0 |
count-number-of-maximum-bitwise-or-subsets | ✅ Simple Java Solution | simple-java-solution-by-harsh__005-kyad | CODE\nJava []\nprivate void solve(int[] nums, int i, int n, int xor, int[] res) {\n\tif(i == n) {\n\t\tif(xor == res[0]) res[1]++;\n\t\telse if(xor > res[0]) {\ | Harsh__005 | NORMAL | 2024-10-18T02:55:17.667382+00:00 | 2024-10-18T02:55:17.667426+00:00 | 87 | false | ## **CODE**\n```Java []\nprivate void solve(int[] nums, int i, int n, int xor, int[] res) {\n\tif(i == n) {\n\t\tif(xor == res[0]) res[1]++;\n\t\telse if(xor > res[0]) {\n\t\t\tres[0] = xor;\n\t\t\tres[1] = 1;\n\t\t}\n\t\treturn;\n\t}\n\tsolve(nums, i+1, n, xor|nums[i], res);\n\tsolve(nums, i+1, n, xor, res);\n}\n\npub... | 2 | 0 | ['Java'] | 1 |
count-number-of-maximum-bitwise-or-subsets | Rust | 1-liner | rust-1-liner-by-jsusi-36ch | Code\nrust []\nimpl Solution {\n pub fn count_max_or_subsets(nums: Vec<i32>) -> i32 {\n (0..1 << nums.len())\n .fold((0, 0), |(count, max_b | JSusi | NORMAL | 2024-10-18T01:54:25.204683+00:00 | 2024-10-22T15:46:29.994754+00:00 | 53 | false | # Code\n```rust []\nimpl Solution {\n pub fn count_max_or_subsets(nums: Vec<i32>) -> i32 {\n (0..1 << nums.len())\n .fold((0, 0), |(count, max_bo), combo| {\n nums\n .iter()\n .enumerate()\n .filter_map(|(i, num)| ((combo >> i)... | 2 | 0 | ['Rust'] | 1 |
count-number-of-maximum-bitwise-or-subsets | Rust solution beats 100%, backtracking | rust-solution-beats-100-backtracking-by-qb0v7 | Code\nrust []\nimpl Solution {\n pub fn bt(i: usize, mut v: i32, m: i32, nums: &Vec<i32>) -> i32 {\n if i == nums.len() {\n if v == m { ret | sunjesse | NORMAL | 2024-10-18T00:22:23.213288+00:00 | 2024-10-18T00:22:23.213319+00:00 | 137 | false | # Code\n```rust []\nimpl Solution {\n pub fn bt(i: usize, mut v: i32, m: i32, nums: &Vec<i32>) -> i32 {\n if i == nums.len() {\n if v == m { return 1; }\n return 0;\n }\n Self::bt(i+1, v | nums[i], m, nums) + Self::bt(i+1, v, m, nums)\n }\n\n pub fn count_max_or_subse... | 2 | 0 | ['Rust'] | 3 |
count-number-of-maximum-bitwise-or-subsets | Simple python3 solution | 11 ms - faster than 100.00% solutions | simple-python3-solution-11-ms-faster-tha-za89 | Complexity\n- Time complexity: O(n \cdot 2^n)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(2^n)\n Add your space complexity here, e.g. O | tigprog | NORMAL | 2024-01-16T11:40:37.355137+00:00 | 2024-10-18T00:11:34.247635+00:00 | 148 | false | # Complexity\n- Time complexity: $$O(n \\cdot 2^n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(2^n)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n``` python3 []\nclass Solution:\n def countMaxOrSubsets(self, nums: List[int]) -> int:\n max_or = 0\n... | 2 | 0 | ['Dynamic Programming', 'Bit Manipulation', 'Python3'] | 1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.