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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
add-to-array-form-of-integer | Easy Beginner Friendly Python Solution :) | easy-beginner-friendly-python-solution-b-3hy6 | Easy Beginner Friendly Python Solution :)\n Describe your first thoughts on how to solve this problem. \n\n\n# Run Time\n Describe your approach to solving the | oshine_chan | NORMAL | 2023-07-30T20:14:50.726386+00:00 | 2023-08-02T18:35:47.611149+00:00 | 214 | false | # Easy Beginner Friendly Python Solution :)\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n\n# Run Time\n<!-- Describe your approach to solving the problem. -->\nBeats 98.87%\n\n# Memory\n<!-- Describe your approach to solving the problem. -->\nBeats 62.89%\n\n\n\n# Code\n```\nclass Solution:\n... | 2 | 0 | ['Python3'] | 1 |
maximum-or | ✅Easiest solution | PREFIX-SUFFIX | c++ | easiest-solution-prefix-suffix-c-by-rish-fycl | IMPORTANT\nYou can watch the biggest sliding window series on entire internet just using single template by clicking my profile icon and checking my youtube cha | rishi800900 | NORMAL | 2023-05-13T16:04:13.161916+00:00 | 2023-05-26T17:12:49.336226+00:00 | 7,632 | false | #### IMPORTANT\nYou can watch the biggest sliding window series on entire internet just using single template by clicking my profile icon and checking my youtube channel link from the bio. ( I bet you can solve any sliding window question on leetcode after watching the series do share you thoughts on the same.)\nThanky... | 59 | 3 | [] | 15 |
maximum-or | [C++, Java, Python] Intuition with Explanation | Proof of Why? | Time: O(n) | c-java-python-intuition-with-explanation-g72t | Intuition\nMultiply by $2$ means left shift by $1$. We can left shift some numbers but at most $k$ times in total. To maximize the result we should generate set | shivamaggarwal513 | NORMAL | 2023-05-13T19:56:24.657806+00:00 | 2023-05-15T16:01:48.101483+00:00 | 1,950 | false | # Intuition\nMultiply by $2$ means left shift by $1$. We can left shift some numbers but at most $k$ times in total. To maximize the result we should generate set bits in the most significant part of numbers.\n\nTake this array\n```\n 5 - 000000000101\n 6 - 000000000110\n 9 - 000000001001\n20 - 000000010100\n23 - 00000... | 40 | 0 | ['Bit Manipulation', 'Prefix Sum', 'C++', 'Java', 'Python3'] | 6 |
maximum-or | [Java/C++/Python] Easy One Pass | javacpython-easy-one-pass-by-lee215-zatt | Intuition\nThe best plan is to double the same number k times\nthis will shift the leftmost bit to left k bits.\n\n\n# Explanation\nright[i] = A[i + 1] * A[i + | lee215 | NORMAL | 2023-05-13T16:48:15.829149+00:00 | 2023-05-13T16:51:33.391309+00:00 | 3,107 | false | # **Intuition**\nThe best plan is to double the same number `k` times\nthis will shift the leftmost bit to left `k` bits.\n<br>\n\n# **Explanation**\n`right[i] = A[i + 1] * A[i + 2] * ... * A[n - 1]`\n`left[i] = A[0] * A[1] * ... * A[i - 1]`\n\nSo the result for doubling `A[i]` is\n`left[i] | A[i] << k | right[i]`.\n\n... | 37 | 1 | ['C', 'Python', 'Java'] | 8 |
maximum-or | O(1) space: keep track of bits, super simple to understand and detailed explanation | o1-space-keep-track-of-bits-super-simple-mx2g | Glossary:\n- bit set: ith bit is set means the ith bit equals one \n- highest bit of a number: highest i for which the ith bit is set (eg. in 1001 the highest b | ricola | NORMAL | 2023-05-13T16:28:30.402359+00:00 | 2023-05-14T08:52:10.235605+00:00 | 2,727 | false | Glossary:\n- *bit set*: ith bit is set means the ith bit equals one \n- *highest bit of a number*: highest `i` for which the ith bit is set (eg. in 1001 the highest bit is the 4th bit)\n- *the OR* : `nums[0] | nums[1] | ... | nums[n - 1]`, after one operation (not necessarily the final result)\n\n\nExplanation\n\n1. W... | 30 | 1 | ['Java'] | 7 |
maximum-or | Explained - Very simple & easy to understand solution | explained-very-simple-easy-to-understand-55c0 | Up vote if you like the solution \n# Approach \n1. Evaluate 2^k\n2. Then calculate prefix & suffix bit wise value and store it\n3. check each number by multiply | kreakEmp | NORMAL | 2023-05-13T16:15:46.909832+00:00 | 2023-05-13T17:54:32.571368+00:00 | 4,696 | false | <b>Up vote if you like the solution </b>\n# Approach \n1. Evaluate 2^k\n2. Then calculate prefix & suffix bit wise value and store it\n3. check each number by multiplying 2^k, if it has max ans or not.\n\nQ. Why this works :\nAns : When we multiply a number by 2 then this equal to shifting the values to the left by 1 ... | 24 | 3 | ['C++'] | 8 |
maximum-or | Java easy with explanation. | java-easy-with-explanation-by-rupdeep-084r | Approach\nTo solve this problem, we can use the approach of calculating prefix and suffix sums. For each element in the array, we can calculate the maximum poss | Rupdeep | NORMAL | 2023-05-13T16:02:35.122237+00:00 | 2023-05-13T16:02:35.122276+00:00 | 1,764 | false | # Approach\nTo solve this problem, we can use the approach of calculating prefix and suffix sums. For each element in the array, we can calculate the maximum possible value of nums[0] | nums[1] | ... | nums[n - 1] by multiplying it by 2^k and bitwise ORing it with the prefix sum of the elements before it and the suffix... | 11 | 1 | ['Java'] | 1 |
maximum-or | Dynamic programming not working || solution using prefix array | dynamic-programming-not-working-solution-09iv | Intuition\n Describe your first thoughts on how to solve this problem. \nThis approach is not working for test case -> 6,9,8 and k = 1\nthe ans should be 31 and | satyamkant2805 | NORMAL | 2023-05-13T16:03:28.524554+00:00 | 2023-05-16T10:10:52.520628+00:00 | 1,261 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThis approach is not working for test case -> 6,9,8 and k = 1\nthe ans should be 31 and my code is giving 30... \nto get answer we multiply 8 by 2 so array will be [6,9,16]\n\nthe dp code is not taking 9|16 (25) as return value instead it... | 10 | 1 | ['Dynamic Programming', 'Recursion', 'C++'] | 2 |
maximum-or | Python simple greedy O(n) Time O(1) Memory | python-simple-greedy-on-time-o1-memory-b-ica4 | \n\n# Code\n\nclass Solution:\n def maximumOr(self, nums: List[int], k: int) -> int:\n cur = 0\n saved = 0\n for num in nums:\n | Yigitozcelep | NORMAL | 2023-05-13T16:00:36.493461+00:00 | 2023-05-13T16:23:10.964003+00:00 | 1,347 | false | \n\n# Code\n```\nclass Solution:\n def maximumOr(self, nums: List[int], k: int) -> int:\n cur = 0\n saved = 0\n for num in nums:\n saved |= num & cur\n cur |= num\n \n max_num = 0\n \n for num in nums:\n max_num = max(max_num, saved | ... | 9 | 0 | ['Greedy', 'Python3'] | 6 |
maximum-or | Step by step explanation || best Solution | step-by-step-explanation-best-solution-b-nwjh | Intuition\n1. We start with the most significant bit (30th bit assuming the maximum value of elements in nums is less than 2^30) and iterate downwards.\n2. In e | raunakkodwani | NORMAL | 2023-05-13T17:39:19.902638+00:00 | 2023-05-13T17:39:19.902688+00:00 | 496 | false | # Intuition\n1. We start with the most significant bit (30th bit assuming the maximum value of elements in `nums` is less than 2^30) and iterate downwards.\n2. In each iteration, we count the number of elements in `nums` that have the current bit set to 1.\n3. If the count is greater than `k` or if setting the current ... | 8 | 0 | ['C++'] | 0 |
maximum-or | EASY C++ USING PREFIX AND SUFFIX SUM | easy-c-using-prefix-and-suffix-sum-by-sp-k99f | Intuition\nWe have to check on each element weather we can give multiply it for k times. Multiplying single element k time will give more larger result.\n\n# Ap | sparrow_harsh | NORMAL | 2023-05-13T16:03:15.561901+00:00 | 2023-05-13T16:06:59.336023+00:00 | 2,371 | false | # Intuition\nWe have to check on each element weather we can give multiply it for k times. Multiplying single element k time will give more larger result.\n\n# Approach\nwe will store prefix and suffix or of each index in order to minimise time complexity.\n\nafter that we can iterate on each index multifly it with 2 f... | 8 | 1 | ['C++'] | 3 |
maximum-or | Python 3 || 7 lines, w/explanation || T/S: 99% / 99% | python-3-7-lines-wexplanation-ts-99-99-b-13hj | Here\'s the plan:\n1. We determine the maximum number of bits for elements innums.\n2. We compile those elements innumsthat have the maximum number of bits (n) | Spaulding_ | NORMAL | 2023-05-17T17:02:17.882876+00:00 | 2024-06-19T23:40:25.237536+00:00 | 610 | false | Here\'s the plan:\n1. We determine the maximum number of bits for elements in`nums`.\n2. We compile those elements in`nums`that have the maximum number of bits (`n`) in the array`cands`. (The answer will be determined by left-shifting one of these elements.)\n3. We iterate through`nums`, keeping track of the bits seen ... | 7 | 0 | ['Python', 'Python3'] | 1 |
maximum-or | Prefix & Suffix - Detailed Explaination | prefix-suffix-detailed-explaination-by-t-ar8u | \nclass Solution:\n def maximumOr(self, nums: List[int], k: int) -> int:\n n, res = len(nums), 0\n pre, suf = [0] * n, [0] * n\n # calcu | __wkw__ | NORMAL | 2023-05-14T06:11:30.958441+00:00 | 2023-05-14T07:31:57.682620+00:00 | 229 | false | ```\nclass Solution:\n def maximumOr(self, nums: List[int], k: int) -> int:\n n, res = len(nums), 0\n pre, suf = [0] * n, [0] * n\n # calculate the prefix OR \n for i in range(n - 1): pre[i + 1] = pre[i] | nums[i]\n # calculate the suffix OR\n for i in range(n - 1, 0, -1): s... | 6 | 0 | ['Prefix Sum', 'Python'] | 0 |
maximum-or | ✅ Easy Segment Tree Approach| Intuitive Solution| C++ code | easy-segment-tree-approach-intuitive-sol-m87r | Intuition\nSince its a range query and update so we should think of Segment tree approach\n# Approach\nSince its given that we can multiply the array elements b | ampish | NORMAL | 2023-05-13T16:06:49.834836+00:00 | 2023-05-13T16:13:13.104523+00:00 | 1,265 | false | # Intuition\nSince its a range query and update so we should think of Segment tree approach\n# Approach\nSince its given that we can multiply the array elements by 2, it indirectly means that we can right shift the array elements k times.\nNow,\nFirstly we should think how many values should be affected by the operatio... | 6 | 0 | ['C++'] | 0 |
maximum-or | WA on new testcases | Try All Ways | Bottom Up & Top Down DP | Try all ways | C++ | Java | wa-on-new-testcases-try-all-ways-bottom-09jc1 | Idea:\nKnapSack -> Pick or not pick\nPick, how many times we can multiply current number by 2, then do OR\nSkip, just do OR and move to next\n\nC++\nTop Down\n\ | hwaiting_dk | NORMAL | 2023-05-13T16:02:06.049531+00:00 | 2023-05-16T14:08:22.142176+00:00 | 1,409 | false | **Idea:**\nKnapSack -> Pick or not pick\nPick, how many times we can multiply current number by 2, then do `OR`\nSkip, just do `OR` and move to next\n\nC++\n**Top Down**\n```\n// TC: O(N * K * K)\n// SC: O(N * K)\n#define ll long long\nclass Solution {\n ll memo[100001][16];\n\n ll rec(vector<int> &arr, int i, in... | 6 | 0 | ['Dynamic Programming'] | 2 |
maximum-or | O(n) Time Simple Greedy Algorithm Beats 100% | on-time-simple-greedy-algorithm-beats-10-zbv6 | Intuition\n Describe your first thoughts on how to solve this problem. \nWe will always use a single element to apply k operations on it \n# Approach\n Describ | hakkiot | NORMAL | 2024-01-22T15:03:57.620946+00:00 | 2024-01-23T03:43:28.902411+00:00 | 86 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe will always use a single element to apply $$k$$ operations on it \n# Approach\n<!-- Describe your approach to solving the problem. -->\nApply $$k$$ steps on every $$a[i]$$ and return the maximum of all\n# Complexity\n- Time complexity... | 4 | 0 | ['C++'] | 0 |
maximum-or | SUFFIX || PREFIX || C++ || EASY TO UNDERSTNAD | suffix-prefix-c-easy-to-understnad-by-ga-cxa0 | Code\n\nclass Solution {\npublic:\n long long maximumOr(vector<int>& nums, int k) {\n int n = nums.size(),i;\n if(n==1)return ((nums[0]*1LL)<<k | ganeshkumawat8740 | NORMAL | 2023-05-13T18:44:13.049845+00:00 | 2023-05-13T18:49:44.467231+00:00 | 721 | false | # Code\n```\nclass Solution {\npublic:\n long long maximumOr(vector<int>& nums, int k) {\n int n = nums.size(),i;\n if(n==1)return ((nums[0]*1LL)<<k);\n vector<int> p(n,0),s(n,0);\n p[0] = nums[0];\n for(i = 1; i < n; i++){\n p[i] = (p[i-1]|nums[i]);\n }\n ... | 4 | 0 | ['Array', 'Dynamic Programming', 'Suffix Array', 'Prefix Sum', 'C++'] | 1 |
maximum-or | Using Prefix Method | C++ Easy Solution | using-prefix-method-c-easy-solution-by-k-mudc | Intuition\n Describe your first thoughts on how to solve this problem. \nWe know that there should be only one number that should be multipled by 2^k as every t | kaptan01 | NORMAL | 2023-05-13T16:05:38.191892+00:00 | 2023-05-13T16:13:08.395622+00:00 | 1,093 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe know that there should be only one number that should be multipled by 2^k as every time we multiply a number by 2 there will be shift in a bit of that number, so that number became larger and larger.\n# Approach\n<!-- Describe your app... | 4 | 0 | ['Dynamic Programming', 'Prefix Sum', 'C++'] | 0 |
maximum-or | Python | Greedy | python-greedy-by-aryonbe-spca | Code\n\nfrom collections import Counter\nclass Solution:\n def maximumOr(self, nums: List[int], k: int) -> int:\n counter = [0]*32\n for num in | aryonbe | NORMAL | 2023-05-13T16:02:33.033907+00:00 | 2023-05-13T16:02:33.033949+00:00 | 907 | false | # Code\n```\nfrom collections import Counter\nclass Solution:\n def maximumOr(self, nums: List[int], k: int) -> int:\n counter = [0]*32\n for num in nums:\n for i in range(32):\n counter[i] += num & 1\n num = num >> 1\n res = 0\n for j, num in enum... | 4 | 1 | ['Python3'] | 1 |
maximum-or | ✅ [ CPP ] | Very Easy Solution | No DP | cpp-very-easy-solution-no-dp-by-rushi_mu-163l | \n#### Intuition:\n Intuition of this problem is little bit tricky\n In this question we need to do k operations on any elements. In an operation, we choose an | rushi_mungse | NORMAL | 2023-05-13T16:01:43.873085+00:00 | 2023-05-13T16:05:33.414953+00:00 | 1,003 | false | \n#### Intuition:\n* Intuition of this problem is little bit tricky\n* In this question we need to do k operations on any elements. In an operation, we choose an element and `multiply it by 2`. \n* Above information says in one operation we `shift all bits to left by 1` -> `2 * num == (num << 1)` \n* In our solution we... | 4 | 1 | ['C++'] | 3 |
maximum-or | Greedy and prefix OR | greedy-and-prefix-or-by-hobiter-bqt5 | Intuition\n Describe your first thoughts on how to solve this problem. \nYou need to put all k to one element to make sure the lest most 1;\nHowever, the elemen | hobiter | NORMAL | 2023-05-15T06:28:32.489419+00:00 | 2023-05-15T06:28:32.489462+00:00 | 279 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nYou need to put all k to one element to make sure the lest most 1;\nHowever, the element is not necessary the largest element, eg:\n[100000001,\n100000010,\n100]\nk = 1,\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity h... | 3 | 0 | ['Java'] | 0 |
maximum-or | Python Elegant & Short | O(n) | Prefix Sum | python-elegant-short-on-prefix-sum-by-ky-5lhk | Complexity\n- Time complexity: O(n)\n- Space complexity: O(n)\n\n# Code\n\nclass Solution:\n def maximumOr(self, nums: List[int], k: int) -> int:\n n | Kyrylo-Ktl | NORMAL | 2023-05-14T20:32:35.512977+00:00 | 2023-05-14T20:32:35.513018+00:00 | 401 | false | # Complexity\n- Time complexity: $$O(n)$$\n- Space complexity: $$O(n)$$\n\n# Code\n```\nclass Solution:\n def maximumOr(self, nums: List[int], k: int) -> int:\n n = len(nums)\n\n right = [0] * n\n for i in reversed(range(n - 1)):\n right[i] = right[i + 1] | nums[i + 1]\n\n left... | 3 | 0 | ['Prefix Sum', 'Python', 'Python3'] | 0 |
maximum-or | max( bits from multiple numbers OR bits from any number not in current number OR num LSH k ) | max-bits-from-multiple-numbers-or-bits-f-qo9c | Time complexity: $O(n)$ - we iterate over nums twice\n- Space complexity: $O(1)$ - we use constant auxiliary memory with 6 temporary variables\ngolang []\nfunc | dtheriault | NORMAL | 2023-05-13T16:25:10.623922+00:00 | 2023-05-13T17:52:37.207456+00:00 | 197 | false | - Time complexity: $O(n)$ - we iterate over nums twice\n- Space complexity: $O(1)$ - we use constant auxiliary memory with 6 temporary variables\n```golang []\nfunc maximumOr(nums []int, k int) int64 {\n // O(n) - determine bits that appear in multiple numbers and those that appear in any number\n appearsInMultip... | 3 | 0 | ['Go', 'TypeScript', 'Python3', 'JavaScript'] | 0 |
maximum-or | Easy C++ solution using prefix and suffix | easy-c-solution-using-prefix-and-suffix-x1e32 | Intuition\nApply the operation k time on single element only.\n Describe your first thoughts on how to solve this problem. \n\n# Approach\nMaintain prefix and s | Sachin_Kumar_Sharma | NORMAL | 2024-01-29T13:04:38.601060+00:00 | 2024-01-29T13:04:38.601086+00:00 | 10 | false | # Intuition\nApply the operation k time on single element only.\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nMaintain prefix and suffix vector which keep the track of the OR of all the elements left to i and right to i respectively.\n<!-- Describe your approach to solving the prob... | 2 | 0 | ['C++'] | 0 |
maximum-or | Why (num << k) explanation | Simple & Easy step by step thinking process | Easy | Prefix Sum | C++ | why-num-k-explanation-simple-easy-step-b-oxgv | Intuition\n Describe your first thoughts on how to solve this problem. \nWe start by checking the binary representation of the numbers.\n\nLet\'s take an exampl | initial1ze | NORMAL | 2023-08-23T18:40:52.005369+00:00 | 2023-08-24T04:47:21.222299+00:00 | 58 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe start by checking the binary representation of the numbers.\n\nLet\'s take an example: \n\n`nums = [1,2], k = 2`\n\nWe write the numbers in their binary represenations.\n\n1 -> `1` | 2 -> `10`\n\n**Observation 1:** The maximum number t... | 2 | 0 | ['Bit Manipulation', 'Prefix Sum', 'C++'] | 0 |
maximum-or | CPP Solution using prefix OR and suffix OR | cpp-solution-using-prefix-or-and-suffix-phxr8 | \n# Code\n\nclass Solution {\npublic:\n long long maximumOr(vector<int>& l, int k) {\n vector<long long> nums(l.size());\n int n = nums.size(); | sxmbaka | NORMAL | 2023-05-16T09:20:35.673996+00:00 | 2023-05-16T09:20:35.674034+00:00 | 556 | false | \n# Code\n```\nclass Solution {\npublic:\n long long maximumOr(vector<int>& l, int k) {\n vector<long long> nums(l.size());\n int n = nums.size();\n for (int i = 0; i < n; i++) nums[i] = l[i];\n vector<int> pr(n), sf(n);\n pr[0] = nums[0];\n sf[n-1]=nums[n-1];\n for (... | 2 | 0 | ['C++'] | 2 |
maximum-or | 🔥Java || Prefix - Suffix | java-prefix-suffix-by-neel_diyora-sfq3 | 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# Co | anjan_diyora | NORMAL | 2023-05-14T05:14:43.764221+00:00 | 2023-05-14T05:14:43.764253+00:00 | 398 | 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 long maximumOr(int[] nums, int k) {\n if(nums.length == 1) {\n return (long)nums... | 2 | 0 | ['Java'] | 0 |
maximum-or | Python3 Solution | python3-solution-by-motaharozzaman1996-65ef | \n\nclass Solution:\n def maximumOr(self, nums: List[int], k: int) -> int:\n cur = 0\n saved = 0\n for num in nums:\n saved | | Motaharozzaman1996 | NORMAL | 2023-05-13T18:39:23.269620+00:00 | 2023-05-13T18:39:23.269681+00:00 | 149 | false | \n```\nclass Solution:\n def maximumOr(self, nums: List[int], k: int) -> int:\n cur = 0\n saved = 0\n for num in nums:\n saved |= num & cur\n cur |= num\n \n max_num = 0\n \n for num in nums:\n max_num = max(max_num, saved | (cur & ~nu... | 2 | 1 | ['Python', 'Python3'] | 1 |
maximum-or | Prefix - Suffix with intuitiion -> why to increase only one element why not spread it. | prefix-suffix-with-intuitiion-why-to-inc-hv30 | Intuition\n1. or operation\n2. k is very small\n3. multiply with 2 -> left shifting\n\ncorrect statement multiplying the number with left most msb is most benif | Ar_2000 | NORMAL | 2023-05-13T18:12:58.565170+00:00 | 2023-05-13T18:13:57.653396+00:00 | 136 | false | # Intuition\n1. or operation\n2. k is very small\n3. multiply with 2 -> left shifting\n\ncorrect statement multiplying the number with left most msb is most benificial as it will make the or more bigger as it has MSB at.\n\nnow there can be multiple numbers with left most msbs. We have to choose one of them. \nWhich on... | 2 | 0 | ['C++'] | 1 |
maximum-or | [C++] why my Code was not working! , don't use "or" instead of "|" | c-why-my-code-was-not-working-dont-use-o-mqvy | From today onwards,i\'ll remember or == || \nfor logic or always |\nvery disappointed :(\n# Code\n\nclass Solution {\npublic:\n #define ll long long\n ll | Pathak_Ankit | NORMAL | 2023-05-13T16:54:11.343886+00:00 | 2023-05-13T16:54:11.343929+00:00 | 252 | false | From today onwards,i\'ll remember or == || \nfor logic **or** always **|**\nvery disappointed :(\n# Code\n```\nclass Solution {\npublic:\n #define ll long long\n ll memo[100001][16];\n long long rec(int i,int j,vector<int>&nums,int k)\n {\n if(i>=nums.size()) return 0;\n if(memo[i][j] !=- 1) retur... | 2 | 0 | ['Dynamic Programming', 'Recursion', 'Memoization', 'C++'] | 0 |
maximum-or | JS Solution | js-solution-by-cf2-irxu | Intuition\n Describe your first thoughts on how to solve this problem. \nDon\'t forget to use BigInt. That\'s why I didn\'t get it right in the contest.\n# Appr | cf2 | NORMAL | 2023-05-13T16:31:32.156935+00:00 | 2023-05-13T16:33:04.443821+00:00 | 109 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nDon\'t forget to use BigInt. That\'s why I didn\'t get it right in the contest.\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)$$ --... | 2 | 0 | ['JavaScript'] | 0 |
maximum-or | Simple Java solution. | simple-java-solution-by-codehunter01-wy4r | \n\n# Code\n\nclass Solution {\n public long maximumOr(int[] nums, int k) {\n int n = nums.length;\n long[] prefix = new long[n];\n long | codeHunter01 | NORMAL | 2023-05-13T16:03:46.623631+00:00 | 2023-05-13T16:03:46.623672+00:00 | 534 | false | \n\n# Code\n```\nclass Solution {\n public long maximumOr(int[] nums, int k) {\n int n = nums.length;\n long[] prefix = new long[n];\n long[] suffix = new long[n];\n prefix[0] = 0;\n suffix[n-1] = 0;\n for(int i= 1;i<n;i++)\n {\n prefix[i] = prefix[i-1]|num... | 2 | 0 | ['Java'] | 0 |
maximum-or | EASY C++ SOLUTION | easy-c-solution-by-10_adi-o5x3 | Intuition\nBY MULTIPLYING NUMBER BY 2 WILL INCREASE ITS VALUE SO RATHER THAN INCREASING DIFFERNT NUMBERS IN AN ARRAY , WE SHOULD INCREASE INDIVIDUAL NUMBER AND | 10_Adi | NORMAL | 2024-07-17T10:07:47.976966+00:00 | 2024-07-17T10:07:47.977033+00:00 | 8 | false | # Intuition\nBY MULTIPLYING NUMBER BY 2 WILL INCREASE ITS VALUE SO RATHER THAN INCREASING DIFFERNT NUMBERS IN AN ARRAY , WE SHOULD INCREASE INDIVIDUAL NUMBER AND TAKE MAX OF THEM WHICH WILL PROVIDE US WITH MAXIMUM OR VALUE.\n\n# Approach\nPREFIX, SUFFIX OR \n\n# Complexity\n- Time complexity:\nO(N)\n\n- Space complexit... | 1 | 0 | ['C++'] | 0 |
maximum-or | Bit Manipulation approach | TC: O(n) | SC: O(1) | Java solution | Clean Code | bit-manipulation-approach-tc-on-sc-o1-ja-5mvf | Intuition\nLet n = nums.length\nLet\'s assume $k = 1$. We can multiply each number by $2$ one-by-one and for each we will calculate nums[0] | nums[1] | ... | nu | vrutik2809 | NORMAL | 2023-06-28T12:55:42.044498+00:00 | 2023-07-01T10:50:53.794004+00:00 | 43 | false | # Intuition\nLet `n = nums.length`\nLet\'s assume $k = 1$. We can multiply each number by $2$ one-by-one and for each we will calculate `nums[0] | nums[1] | ... | nums[n - 1]`. The answer will be maximum among all of this.\nNow let\'s say $k \\gt 1$. For each $k$ we have $n$ choices to pick. But rathar then picking oth... | 1 | 0 | ['Bit Manipulation', 'Java'] | 0 |
maximum-or | Prefix OR | Suffix OR | C++ | prefix-or-suffix-or-c-by-sankalp0109-6ubk | 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 | sankalp0109 | NORMAL | 2023-05-19T10:02:02.728628+00:00 | 2023-05-19T10:02:02.728663+00:00 | 74 | 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 | ['Array', 'Greedy', 'Bit Manipulation', 'Prefix Sum', 'C++'] | 0 |
maximum-or | Beats 100% | beats-100-by-akdev14-tp4d | 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 | akdev14 | NORMAL | 2023-05-16T08:08:23.034356+00:00 | 2023-05-16T08:08:23.034388+00:00 | 126 | 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 | ['Iterator', 'Java'] | 0 |
maximum-or | Rust/Python. Linear with full math proof (no handwaving, only math) | rustpython-linear-with-full-math-proof-n-96hg | Math proof\n\nHere by the size of number I mean a lengh of its binary representation. For example 1011101 has size of 7.\n\nLets assume that we have an array of | salvadordali | NORMAL | 2023-05-15T19:46:03.143350+00:00 | 2023-05-15T19:46:03.143386+00:00 | 150 | false | # Math proof\n\nHere by the size of number I mean a lengh of its binary representation. For example `1011101` has size of `7`.\n\nLets assume that we have an array of numbers where one number has the size of `n` and all other numbers have the size of at most `n - 1`. And now we have `k` operations. Here I will prove th... | 1 | 0 | ['Python', 'Rust'] | 1 |
maximum-or | Easy prefix and suffix approach ✅ || Beats 88% | easy-prefix-and-suffix-approach-beats-88-06am | \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 | neergx | NORMAL | 2023-05-14T09:41:44.430979+00:00 | 2023-05-14T09:41:44.431024+00:00 | 36 | 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```\nclass Solution {\npublic:\n \n long long maximumOr(vector<int>& nums, int k) {\n int n = nums.size();\n l... | 1 | 0 | ['Bit Manipulation', 'Suffix Array', 'Prefix Sum', 'C++'] | 0 |
maximum-or | Python | Prefix | Suffix | python-prefix-suffix-by-dinar-omv0 | I checked several solutions and created my own to see if I understood them correctly.\nThe idea is here to find number with the highest bit_length and save the | dinar | NORMAL | 2023-05-13T23:12:04.366627+00:00 | 2023-05-13T23:12:04.366657+00:00 | 78 | false | I checked several solutions and created my own to see if I understood them correctly.\nThe idea is here to find number with the highest `bit_length` and save the value at `max_bit` and numbers at `max_bit_list`. Meanwhile also find bitwise OR for all other numbers ans keep them in `ans`.\nBecuase we want the maximum bi... | 1 | 0 | ['Python'] | 0 |
maximum-or | Easiest Dynamic Programming solution | |C++ | easiest-dynamic-programming-solution-c-b-k6ys | What you have to do is basically check if all different combinations of number when multiplied with 2 give the maximum bitwise OR or they do not.\nSimple knaps | shashankyadava08 | NORMAL | 2023-05-13T21:34:20.811099+00:00 | 2023-05-13T21:34:58.341798+00:00 | 107 | false | What you have to do is basically check if all different combinations of number when multiplied with 2 give the maximum bitwise OR or they do not.\nSimple knapsack solution.\nTime Complexity is (K* K* N)\nSpace Complexity is (K*N)\n```\nclass Solution {\npublic:\n long long dp[100005][16];\n long long recur(vecto... | 1 | 0 | ['Dynamic Programming', 'Recursion', 'Memoization'] | 1 |
maximum-or | [Python3] Two Counters, Constant Space, Lots of Bit Hacks | python3-two-counters-constant-space-lots-g18p | Disclaimer\nI wasn\'t able to crack this question during the contest; I figured out the trick but wasn\'t able to implement it nor rigorously prove why it works | wlui | NORMAL | 2023-05-13T21:03:26.510762+00:00 | 2023-05-13T21:04:14.409738+00:00 | 25 | false | # Disclaimer\nI wasn\'t able to crack this question during the contest; I figured out the trick but wasn\'t able to implement it nor rigorously prove why it works. Other solutions do a good job with the proof so I\'ll just explain my intuition down below.\n\n# Trick\nWe want to find the maximal array OR (`nums[0] | num... | 1 | 0 | ['Python3'] | 0 |
maximum-or | O(45N) simple | o45n-simple-by-dkravitz78-dk67 | Make an array counting how many times each bit is in a number.\nThen simply loop through each number n and compute what would happen if we doubled it k times. \ | dkravitz78 | NORMAL | 2023-05-13T20:20:37.749093+00:00 | 2023-05-13T20:20:37.749132+00:00 | 69 | false | Make an array counting how many times each bit is in a number.\nThen simply loop through each number n and compute what would happen if we doubled it k times. \nFor each bit i to count, either \n(1) B[i]>1 (will count for sure no matter what is done to n)\n(2) B[i]=1 and (1<<i)&n=0 (changing n won\'t change B[i])\n(3) ... | 1 | 0 | [] | 0 |
maximum-or | Bit-operation, Easy Solution | bit-operation-easy-solution-by-absolute-pfs3r | The key observation is that you should apply all the operations to any one of the element.\nWhy? Any 2^i is greater than the sum of all 2^(0 to i-1)\nor (2^i> | absolute-mess | NORMAL | 2023-05-13T18:59:41.550585+00:00 | 2023-05-13T18:59:41.550632+00:00 | 87 | false | The key observation is that you should apply all the operations to any one of the element.\nWhy? Any 2^i is greater than the sum of all 2^(0 to i-1)\nor (2^i> 2^(i-1)+2^(i-2).....+ 2^0), \nso we will multiply any number k times, so that we get the highest set bit and thus the highest sum.\n\nSolution- We will check fo... | 1 | 0 | ['Bit Manipulation', 'C'] | 0 |
maximum-or | Easy Solution with SC & TC & Intution | easy-solution-with-sc-tc-intution-by-ms9-9f0y | \n# Intution\n 1. We do k operations on ONE picked element => This is because if a number is picked and a operation is done once it is giving max result , then | MSJi | NORMAL | 2023-05-13T17:32:05.885580+00:00 | 2023-05-13T17:33:11.271525+00:00 | 90 | false | \n# Intution\n 1. We do k operations on ONE picked element => This is because if a number is picked and a operation is done once it is giving max result , then this means doing it k times maximisesour ans (we are left shifing each time)\n2. Why not maximum element picked give correct ans?\n \n ->eg: \n ... | 1 | 0 | ['C++'] | 1 |
maximum-or | Prefix OR Current_Element OR Suffix | prefix-or-current_element-or-suffix-by-w-qnr7 | \nclass Solution {\npublic:\n long long maximumOr(vector<int>& nums, int k) {\n int n=nums.size();\n vector<long long>pOR(n),sOR(n);\n p | whorishi | NORMAL | 2023-05-13T17:24:49.807565+00:00 | 2023-05-13T17:24:49.807608+00:00 | 44 | false | ```\nclass Solution {\npublic:\n long long maximumOr(vector<int>& nums, int k) {\n int n=nums.size();\n vector<long long>pOR(n),sOR(n);\n pOR[0]=nums[0];\n sOR[n-1]=nums[n-1];\n \n for(int i=1;i<nums.size();i++)\n {\n pOR[i]=pOR[i-1] | nums[i];\n }\n... | 1 | 0 | ['Bit Manipulation', 'C', 'Suffix Array'] | 0 |
maximum-or | Easy C++ Solution | easy-c-solution-by-5matuag-fdx3 | \n\n# Code\n\nclass Solution {\npublic:\n long long maximumOr(vector<int>& nums, int k) {\n long long ans = 0;\n long long aur = 0;\n ve | 5matuag | NORMAL | 2023-05-13T17:07:59.288281+00:00 | 2023-05-13T17:07:59.288326+00:00 | 20 | false | \n\n# Code\n```\nclass Solution {\npublic:\n long long maximumOr(vector<int>& nums, int k) {\n long long ans = 0;\n long long aur = 0;\n vector<int> setbit(34, 0);\n for (int j = 0; j < nums.size(); j++){\n aur |= nums[j];\n int count = 0;\n int temp = num... | 1 | 0 | ['C++'] | 0 |
maximum-or | EASY CPP SOLUTION || USING PREFIX & SUFIX | easy-cpp-solution-using-prefix-sufix-by-tkl5w | 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 | ankit_kumar12345 | NORMAL | 2023-05-13T16:55:53.218247+00:00 | 2023-05-13T16:55:53.218290+00:00 | 137 | 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:\no(N)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n ... | 1 | 0 | ['C++'] | 0 |
maximum-or | EASY C++ SOLUTION ||PREFIX METHOD | easy-c-solution-prefix-method-by-khushie-61d0 | 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 | khushiesharma | NORMAL | 2023-05-13T16:47:39.664534+00:00 | 2023-05-13T16:47:39.664570+00:00 | 26 | 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)$$ -->O(n) overall\n\n- Space complexity:\n<!-- Add your space complexity here, e.g.... | 1 | 0 | ['C++'] | 1 |
maximum-or | Rust Counting the bits | rust-counting-the-bits-by-xiaoping3418-yua5 | Intuition\n Describe your first thoughts on how to solve this problem. \nSince k <= 15, we can only select one number to apply all the operations. \n# Approach\ | xiaoping3418 | NORMAL | 2023-05-13T16:47:38.605446+00:00 | 2023-05-13T17:00:37.961214+00:00 | 50 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nSince k <= 15, we can only select one number to apply all the operations. \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)$$ -->\nO(... | 1 | 0 | ['Rust'] | 0 |
maximum-or | Prefix OR | prefix-or-by-votrubac-vw96 | I first solved this problem by trying to find the best number to double for each iteration of k.\n\nWrong Answer.\n\nThen I realize that you just need to pick o | votrubac | NORMAL | 2023-05-13T16:45:26.356326+00:00 | 2023-05-13T17:00:43.412581+00:00 | 104 | false | I first solved this problem by trying to find the best number to double for each iteration of `k`.\n\nWrong Answer.\n\nThen I realize that you just need to pick one number and double it `k` times. \n\n**C++**\n```cpp\nlong long maximumOr(vector<int>& nums, int k) {\n vector<int> pref_or{0};\n partial_sum(begin(nu... | 1 | 1 | ['C'] | 0 |
maximum-or | Prefix and Suffix Array Bitwise Or -Simple and Easy O(n) | prefix-and-suffix-array-bitwise-or-simpl-4ke0 | 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 | Lee_fan_Ak_The_Boss | NORMAL | 2023-05-13T16:34:26.686529+00:00 | 2023-05-13T16:34:26.686623+00:00 | 334 | 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 | ['Python', 'C++', 'Java', 'Python3'] | 1 |
maximum-or | C++|Most Easy Intuitive Solution | cmost-easy-intuitive-solution-by-arko-81-91f4 | \nclass Solution {\npublic:\n typedef long long ll;\n long long maximumOr(vector<int>& nums, int k) {\n int n=nums.size();\n vector<int> pre | Arko-816 | NORMAL | 2023-05-13T16:32:48.599915+00:00 | 2023-05-13T16:32:48.599941+00:00 | 57 | false | ```\nclass Solution {\npublic:\n typedef long long ll;\n long long maximumOr(vector<int>& nums, int k) {\n int n=nums.size();\n vector<int> pref(n,0);\n vector<int> suff(n,0);\n pref[0]=nums[0];\n suff[n-1]=nums[n-1];\n for(int i=1;i<n;i++)\n pref[i]=pref[i-1]|... | 1 | 0 | [] | 0 |
maximum-or | Prefix and Suffix OR | prefix-and-suffix-or-by-_kitish-ss0n | Code\n\ntypedef long long ll;\nclass Solution {\npublic:\n long long maximumOr(vector<int>& nums, int k) {\n ll val = 1, n = size(nums);\n for( | _kitish | NORMAL | 2023-05-13T16:21:15.920194+00:00 | 2023-05-13T16:21:15.920227+00:00 | 75 | false | # Code\n```\ntypedef long long ll;\nclass Solution {\npublic:\n long long maximumOr(vector<int>& nums, int k) {\n ll val = 1, n = size(nums);\n for(int i=1; i<=k; ++i) val *= 2;\n vector<ll> pre(n),suff(n);\n pre[0] = nums[0];\n suff[n-1] = nums[n-1];\n for(int i=1; i<n; ++i... | 1 | 0 | ['Greedy', 'Suffix Array', 'Prefix Sum', 'Bitmask', 'C++'] | 0 |
maximum-or | C++ | Using Precomputation | c-using-precomputation-by-deepak_2311-7zlh | 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 | godmode_2311 | NORMAL | 2023-05-13T16:14:40.304406+00:00 | 2023-05-13T17:13:29.382065+00:00 | 135 | 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 {\npublic:\n \n // check current element is creating maximum OR or not\n long long checkForCurrent(lo... | 1 | 0 | ['Array', 'Bit Manipulation', 'Suffix Array', 'Prefix Sum', 'C++'] | 0 |
maximum-or | Greedy | Java | greedy-java-by-viatsevskyi-9vr3 | \nDue to problem constraints, the best strategy is to select a single number from the array and shift it by K. To achieve this efficiently, we should precompute | viatsevskyi | NORMAL | 2023-05-13T16:05:25.394198+00:00 | 2023-05-13T16:18:33.538958+00:00 | 29 | false | \nDue to problem constraints, **the best strategy is to select a single number from the array and shift it by K.** To achieve this efficiently, we should precompute the array\'s results without any shifts. For each element, we subtract it from the precomputed result and apply a K-shift using the bitwise OR operation to... | 1 | 1 | [] | 0 |
maximum-or | Prefix and suffix arrays | prefix-and-suffix-arrays-by-_srahul-sv18 | Intuition\n1. Make a Prefix OR & Suffix OR array.\n2. Now try to traverse the array and maximise the \nprefix[i-1] | nums[i]*2^k | suffix[i+1],\n\nthat means fo | _srahul_ | NORMAL | 2023-05-13T16:05:14.299200+00:00 | 2023-05-13T16:20:03.930722+00:00 | 135 | false | # Intuition\n1. Make a Prefix OR & Suffix OR array.\n2. Now try to traverse the array and maximise the \n```prefix[i-1] | nums[i]*2^k | suffix[i+1]```,\n\nthat means for each ```nums[i]``` we\'re multiplying it with `2^k` ORing it with `prefix[i-1]` and `suffix[i+1]`, and checking if this `nums[i]` is giving us the Max... | 1 | 0 | ['Java'] | 0 |
maximum-or | O(N) Python3 Using Mask of Unique Bits | on-python3-using-mask-of-unique-bits-by-8haqn | Intuition\nThe solution left-shifts a num k times, since that causes the highest possible bit; however, it is unclear which num will need to be shifted.\n\n# Ap | dumbunny8128 | NORMAL | 2023-05-13T16:03:33.156718+00:00 | 2023-05-13T16:08:38.943900+00:00 | 121 | false | # Intuition\nThe solution left-shifts a num k times, since that causes the highest possible bit; however, it is unclear which num will need to be shifted.\n\n# Approach\nWe will check each num to see which num produces the maximum orred value. Prior to iteration, we calculate uniqueMask, the OR of bits that are set in ... | 1 | 1 | ['Python3'] | 0 |
maximum-or | Prefix and suffix array in python. | prefix-and-suffix-array-in-python-by-rya-ueek | Approach\nFor every num in the nums array, we will multiply num by 2^k, and keep a track of the bitwise OR of all the array elements taken together. To perform | ryan-gang | NORMAL | 2023-05-13T16:03:15.642476+00:00 | 2023-05-13T16:04:12.092686+00:00 | 307 | false | # Approach\nFor every num in the nums array, we will multiply num by 2^k, and keep a track of the bitwise OR of all the array elements taken together. To perform this computation optimally, we keep a prefix and a suffix array.\n `prefix[i] = bitwise OR of elements at index 0 to i-1.`\n `suffix[i] = bitwise OR of ... | 1 | 0 | ['Greedy', 'Suffix Array', 'Prefix Sum', 'Python', 'Python3'] | 0 |
maximum-or | Easy to Understand Solution | Prefix | Suffix | easy-to-understand-solution-prefix-suffi-un7l | \n#define ll long long\nclass Solution {\npublic:\n ll mypow(ll a, ll b) {\nll res = 1;\nwhile (b > 0) {\nif (b & 1)\nres = res * a*1ll;\na = a * a*1ll;\nb > | Sankalp_Sharma_29 | NORMAL | 2023-05-13T16:03:12.879732+00:00 | 2023-05-13T16:03:12.879784+00:00 | 30 | false | ```\n#define ll long long\nclass Solution {\npublic:\n ll mypow(ll a, ll b) {\nll res = 1;\nwhile (b > 0) {\nif (b & 1)\nres = res * a*1ll;\na = a * a*1ll;\nb >>= 1;\n}\nreturn res;\n}\n long long maximumOr(vector<int>& nums, int k) {\n int n=nums.size();\n ll x=0;\n if(n==1) return 1ll*nums[... | 1 | 0 | [] | 0 |
maximum-or | [Python 3] Prefix Suffix | python-3-prefix-suffix-by-0xabhishek-2apg | \nclass Solution:\n def maximumOr(self, nums: List[int], k: int) -> int:\n bitwiseOr = lambda x, y: x | y\n \n forward = list(accumulate | 0xAbhishek | NORMAL | 2023-05-13T16:00:57.876540+00:00 | 2023-05-13T16:02:52.367382+00:00 | 456 | false | ```\nclass Solution:\n def maximumOr(self, nums: List[int], k: int) -> int:\n bitwiseOr = lambda x, y: x | y\n \n forward = list(accumulate(nums, bitwiseOr))\n backward = list(accumulate(nums[ : : -1], bitwiseOr))[ : : -1]\n \n forward = [0] + forward[ : -1]\n backwar... | 1 | 0 | ['Bit Manipulation', 'Prefix Sum', 'Python', 'Python3'] | 1 |
maximum-or | EASY C++ SOLUTION || BEGINNER FRIENDLY || EASY TO UNDERSTAND | easy-c-solution-beginner-friendly-easy-t-inn6 | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | suraj_kumar_rock | NORMAL | 2025-04-08T23:38:56.955273+00:00 | 2025-04-08T23:38:56.955273+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 | ['Array', 'Greedy', 'Bit Manipulation', 'Prefix Sum', 'C++'] | 0 |
maximum-or | DP+Slide Window | dpslide-window-by-linda2024-auoa | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | linda2024 | NORMAL | 2025-03-26T19:00:08.846379+00:00 | 2025-03-26T19:00:08.846379+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 | ['C#'] | 0 |
maximum-or | Easy Python Solution | easy-python-solution-by-vidhyarthisunav-v2rv | IntuitionWe compute the prefix OR and suffix OR for the array, then iterate through each element, applying k operations to maximize the result.The above strateg | vidhyarthisunav | NORMAL | 2025-02-18T09:55:47.896343+00:00 | 2025-02-18T09:55:47.896343+00:00 | 2 | false | # Intuition
We compute the prefix OR and suffix OR for the array, then iterate through each element, applying k operations to maximize the result.
The above strategy kicks in through the fact that the optimal approach is to apply all k operations to a single number (why?).
# Code
```python3 []
class Solution:
def... | 0 | 0 | ['Python3'] | 0 |
maximum-or | Max OR || C++ || Explanation for optimal result | max-or-c-explanation-for-optimal-result-qznc9 | IntuitionLeft shift the index since it is multiplied by 2.ApproachThe most optimal approach is to precompute the prefix and suffix or of the vector for each ind | Aditi_71 | NORMAL | 2025-01-30T12:07:54.273300+00:00 | 2025-01-30T12:07:54.273300+00:00 | 6 | false | # Intuition
Left shift the index since it is multiplied by 2.
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
The most optimal approach is to precompute the prefix and suffix or of the vector for each index. Performing k operations on the same value will give maximum result. So the index... | 0 | 0 | ['Bit Manipulation', 'Prefix Sum', 'C++'] | 0 |
maximum-or | JavaScript (nothing new, just use bigint) | javascript-nothing-new-just-use-bigint-b-jxi9 | ApproachReally the same as other solutions out there, but if you dont understand why your solution doesnt work it might be because of the 'number' primitive not | thom-gg | NORMAL | 2025-01-19T10:43:49.072206+00:00 | 2025-01-19T10:43:49.072206+00:00 | 9 | false |
# Approach
Really the same as other solutions out there, but if you dont understand why your solution doesnt work it might be because of the 'number' primitive not being able to properly deal with huge numbers, so use BigInt
# Code
```typescript []
function maximumOr(nums: number[], k: number): number {
// pre... | 0 | 0 | ['TypeScript', 'JavaScript'] | 0 |
maximum-or | 2680. Maximum OR | 2680-maximum-or-by-g8xd0qpqty-zltw | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | G8xd0QPqTy | NORMAL | 2025-01-19T07:01:55.110607+00:00 | 2025-01-19T07:01:55.110607+00:00 | 6 | 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 |
maximum-or | Go right, go left, go right | go-right-go-left-go-right-by-j22qidyza7-z5eg | Code | J22qIDYZa7 | NORMAL | 2024-12-25T04:07:44.049562+00:00 | 2024-12-25T04:07:44.049562+00:00 | 1 | false | # Code
```php []
class Solution
{
/**
* @param Integer[] $nums
* @param Integer $k
* @return Integer
*/
function maximumOr($nums, $k)
{
$len = count($nums);
$temp = array_fill(0, $len, 0);
$sum = 0;
for ($i = 0; $i < $len; $i++) {
$temp[$i] |... | 0 | 0 | ['PHP'] | 0 |
maximum-or | ❄ Easy Java Solution❄Beats 100% of Java Users . | easy-java-solutionbeats-100-of-java-user-xbza | 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 | zzzz9 | NORMAL | 2024-11-27T16:15:20.258655+00:00 | 2024-11-27T16:15:39.472255+00:00 | 1 | 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)$$ --... | 0 | 0 | ['Array', 'Greedy', 'Bit Manipulation', 'Prefix Sum', 'Java'] | 0 |
maximum-or | scala oneliner | scala-oneliner-by-vititov-awjr | scala []\nobject Solution {\n def maximumOr(nums: Array[Int], k: Int): Long =\n (nums.iterator zip (\n nums.toList.scanLeft(0)(_ | _).init \n zip | vititov | NORMAL | 2024-10-31T21:07:18.326566+00:00 | 2024-10-31T21:07:18.326598+00:00 | 0 | false | ```scala []\nobject Solution {\n def maximumOr(nums: Array[Int], k: Int): Long =\n (nums.iterator zip (\n nums.toList.scanLeft(0)(_ | _).init \n zip \n nums.reverseIterator.scanLeft(0)(_ | _).toList.reverse.tail\n ))\n .map{case (num,(p,s)) => (num.toLong<<k)|p|s}.max \n}\n``` | 0 | 0 | ['Scala'] | 0 |
maximum-or | CPP Optimized Solution with 100% better Runtime and Memory | cpp-optimized-solution-with-100-better-r-f5fa | Intuition\nThe best approach would be to shift any one of the numbers by k bits. Our bits can be of three types.\n\n- Appearing in no number\n- Appearing in jus | harsh34vardhan | NORMAL | 2024-10-25T05:51:01.838892+00:00 | 2024-10-25T05:51:01.838917+00:00 | 7 | false | # Intuition\nThe best approach would be to shift any one of the numbers by k bits. Our bits can be of three types.\n\n- Appearing in no number\n- Appearing in just one number\n- Appearing in > 1 numbers\n\nNote that the last type of bits will always be set regardless of our operation.\n\n# Approach\nUse two integers, `... | 0 | 0 | ['C++'] | 0 |
maximum-or | Optimized----//////O(n)-Time and Space complexity\\\\\\ | optimized-on-time-and-space-complexity-b-2bj4 | 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# Co | karthickeyan_S | NORMAL | 2024-10-24T07:28:50.959648+00:00 | 2024-10-24T07:28:50.959683+00:00 | 5 | 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```python3 []\nclass Solution:\n def maximumOr(self, nums: List[int], k: int) -> int:\n n = len(nums)\n m = pow(2,k... | 0 | 0 | ['Python3'] | 0 |
maximum-or | [Python3] 79ms, beats 100% | python3-79ms-beats-100-by-l12tc3d4r-ireh | Background\nI know this is briefly explained but I want to share this code as it gets better results than other solutions I\'ve seen here (79ms, beats 100% of p | l12tc3d4r | NORMAL | 2024-10-23T16:39:06.327677+00:00 | 2024-10-23T16:41:50.180631+00:00 | 7 | false | # Background\nI know this is briefly explained but I want to share this code as it gets better results than other solutions I\'ve seen here (79ms, beats 100% of people).\nThe code should be relatively understandable, at least after looking at other solutions\n\n# Intuition\nTo solve the problem as quickly as possible w... | 0 | 0 | ['Python3'] | 0 |
maximum-or | 42ms beats 98.87% solve by prefix and suffix | 42ms-beats-9887-solve-by-prefix-and-suff-jyrh | 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 | albert0909 | NORMAL | 2024-09-18T15:39:31.327865+00:00 | 2024-09-18T15:39:31.327895+00:00 | 2 | 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... | 0 | 0 | ['Array', 'Greedy', 'Bit Manipulation', 'Suffix Array', 'Prefix Sum', 'C++'] | 0 |
maximum-or | Prefix + Suffix Sum & Greedy | prefix-suffix-sum-greedy-by-alexpg-w7df | With bit OR operation we will collect all unique bits in array. When we multiple any number by 2 we shifts all bits to the right by 1. The most benefiting bit b | AlexPG | NORMAL | 2024-09-01T11:00:59.124328+00:00 | 2024-09-01T11:00:59.124358+00:00 | 5 | false | With bit OR operation we will collect all unique bits in array. When we multiple any number by 2 we shifts all bits to the right by 1. The most benefiting bit by shifting is the most significant bit in overall OR result. If we shift that bit to the right by 1 it will have even more significant power. From that observat... | 0 | 0 | ['C++'] | 0 |
maximum-or | Prefix Suffix OR || Super Simple || C++ | prefix-suffix-or-super-simple-c-by-lotus-6xjd | Code\n\nclass Solution \n{\npublic:\n long long maximumOr(vector<int>& nums, int k) \n {\n long long n=nums.size();\n vector<long long> prex | lotus18 | NORMAL | 2024-08-17T11:30:13.721683+00:00 | 2024-08-17T11:30:13.721715+00:00 | 2 | false | # Code\n```\nclass Solution \n{\npublic:\n long long maximumOr(vector<int>& nums, int k) \n {\n long long n=nums.size();\n vector<long long> prexor(n,0), sufxor(n,0);\n prexor[0]=nums[0];\n for(long long x=1; x<nums.size(); x++)\n {\n prexor[x]=(prexor[x-1]|nums[x]);\... | 0 | 0 | ['Bit Manipulation', 'Prefix Sum', 'C++'] | 0 |
maximum-or | Simple Java | (with meme) | simple-java-with-meme-by-arkadeepgr-zqyg | \n# Code\n\nclass Solution {\n public long maximumOr(int[] nums, int k) {\n //Arrays.sort(nums);\n if(nums.length==1)\n return nums[ | arkadeepgr | NORMAL | 2024-08-15T10:43:15.478762+00:00 | 2024-08-15T10:43:15.478790+00:00 | 4 | false | \n# Code\n```\nclass Solution {\n public long maximumOr(int[] nums, int k) {\n //Arrays.sort(nums);\n if(nums.length==1)\n return nums[0]*(int)Math.pow(2,k);\n\n long[] prev = new long[nums.length];\n long[] post = new long[nums.length];\n long res = Integer.MIN_VALUE;\n... | 0 | 0 | ['Java'] | 0 |
maximum-or | Simple Java | (with meme) | simple-java-with-meme-by-arkadeepgr-xhw0 | \n# Code\n\nclass Solution {\n public long maximumOr(int[] nums, int k) {\n //Arrays.sort(nums);\n if(nums.length==1)\n return nums[ | arkadeepgr | NORMAL | 2024-08-15T10:01:23.239015+00:00 | 2024-08-15T10:01:23.239046+00:00 | 7 | false | \n# Code\n```\nclass Solution {\n public long maximumOr(int[] nums, int k) {\n //Arrays.sort(nums);\n if(nums.length==1)\n return nums[0]*(int)Math.pow(2,k);\n\n long[] prev = new long[nums.length];\n long[] post = new long[nums.length];\n long res = Integer.MIN_VALUE;\n... | 0 | 0 | ['Java'] | 0 |
maximum-or | C++ || Prefix and suffix or | c-prefix-and-suffix-or-by-sshivam26-jl1q | \n\n# Code\n\nclass Solution {\npublic:\n long long maximumOr(vector<int>& nums, int k) {\n int n=nums.size();\n if(n==1)return nums[0]<<k;\n | Sshivam26 | NORMAL | 2024-07-31T13:20:24.939937+00:00 | 2024-07-31T13:20:24.939971+00:00 | 1 | false | \n\n# Code\n```\nclass Solution {\npublic:\n long long maximumOr(vector<int>& nums, int k) {\n int n=nums.size();\n if(n==1)return nums[0]<<k;\n vector<long long>pre(n);pre[0]=nums[0];\n for(int i=1;i<n;i++){\n pre[i]=(long long)(nums[i] | pre[i-1]);\n }\n vector<... | 0 | 0 | ['C++'] | 0 |
maximum-or | JavaScript O(n): apply k to a single element | javascript-on-apply-k-to-a-single-elemen-anjx | Intuition\nThe best result appears when we apply k to a single element.\n# Approach\nFor each element, apply all k moves to it, and leave others unchanged. Thus | lilongxue | NORMAL | 2024-07-28T18:27:18.806827+00:00 | 2024-07-28T18:27:18.806853+00:00 | 4 | false | # Intuition\nThe best result appears when we apply k to a single element.\n# Approach\nFor each element, apply all k moves to it, and leave others unchanged. Thus we get n outcomes, and we just need to select the biggest.\nWe can use an array to record the freqs of each bit when we change none of the elements. When we ... | 0 | 0 | ['JavaScript'] | 0 |
maximum-or | Good prefix sum question | good-prefix-sum-question-by-heramb_ralla-o8ku | 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 | Heramb_Rallapally3112 | NORMAL | 2024-07-11T10:45:39.196578+00:00 | 2024-07-11T10:45:39.196619+00:00 | 1 | 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)$$ --... | 0 | 0 | ['C++'] | 0 |
maximum-or | Good prefix sum question | good-prefix-sum-question-by-heramb_ralla-yjqe | 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 | Heramb_Rallapally3112 | NORMAL | 2024-07-11T10:43:24.652228+00:00 | 2024-07-11T10:43:24.652271+00:00 | 1 | 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)$$ --... | 0 | 0 | ['C++'] | 0 |
maximum-or | C++ solution | c-solution-by-oleksam-kqh4 | \n// Please, upvote if you like it. Thanks :-)\nlong long maximumOr(vector<int>& nums, int k) {\n\tint sz = nums.size();\n\tvector<long long> pref(sz, nums[0]), | oleksam | NORMAL | 2024-07-01T20:06:54.842511+00:00 | 2024-07-01T20:06:54.842548+00:00 | 3 | false | ```\n// Please, upvote if you like it. Thanks :-)\nlong long maximumOr(vector<int>& nums, int k) {\n\tint sz = nums.size();\n\tvector<long long> pref(sz, nums[0]), suff(sz, nums[sz - 1]);\n\tfor (int i = 1; i < sz; i++)\n\t\tpref[i] = pref[i - 1] | nums[i];\n\tfor (int i = sz - 2; i >= 0; i--)\n\t\tsuff[i] = suff[i + 1... | 0 | 0 | ['C', 'C++'] | 0 |
maximum-or | Python Medium | python-medium-by-lucasschnee-howb | \nclass Solution:\n def maximumOr(self, nums: List[int], k: int) -> int:\n \'\'\'\n one operation, double an element\n\n 1001\n 1 | lucasschnee | NORMAL | 2024-06-11T15:16:20.484749+00:00 | 2024-06-11T15:16:20.484781+00:00 | 3 | false | ```\nclass Solution:\n def maximumOr(self, nums: List[int], k: int) -> int:\n \'\'\'\n one operation, double an element\n\n 1001\n 1100\n \n\n \n \'\'\'\n lookup = defaultdict(int)\n ans = 0\n best = 0\n for x in nums:\n best |= ... | 0 | 0 | ['Python3'] | 0 |
maximum-or | another slower approach | another-slower-approach-by-shun_program-cq1g | 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 | Shun_program | NORMAL | 2024-05-28T10:30:56.591601+00:00 | 2024-05-28T10:32:12.401440+00:00 | 0 | 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)$$ --... | 0 | 0 | ['Python'] | 0 |
maximum-or | [C] Greedy | c-greedy-by-leetcodebug-zeix | 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 | leetcodebug | NORMAL | 2024-05-18T11:23:58.788854+00:00 | 2024-05-18T11:23:58.788883+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: $$O(n)$$ \n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(n)$$ \n<!-- Add your space complexity he... | 0 | 0 | ['Array', 'Greedy', 'Bit Manipulation', 'C', 'Prefix Sum'] | 0 |
maximum-or | DP Working! easy intitutive DP solution beats 50% + | dp-working-easy-intitutive-dp-solution-b-6dwe | \n# Complexity\n- Time complexity: O(nk)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(nk)\n Add your space complexity here, e.g. O(n) \n | atulsoam5 | NORMAL | 2024-05-18T05:24:59.760860+00:00 | 2024-05-18T05:24:59.760897+00:00 | 11 | false | \n# Complexity\n- Time complexity: O(n*k)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n*k)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n inline long long int power(long long a, long long b) {\n long long res = 1;\n while (... | 0 | 0 | ['Dynamic Programming', 'Memoization', 'C++'] | 0 |
maximum-or | BitMap Solution, Count the Bits, O(n) time, O(1) space | bitmap-solution-count-the-bits-on-time-o-1egz | Intuition\n1)Go through each num in nums and add the bits that are 1s to the map.\n2)Go through each num in nums and remove the bits from num since we are going | robert961 | NORMAL | 2024-05-09T17:03:55.087294+00:00 | 2024-05-09T17:03:55.087331+00:00 | 5 | false | # Intuition\n1)Go through each num in nums and add the bits that are 1s to the map.\n2)Go through each num in nums and remove the bits from num since we are going to shift this num by << k.(Bit Map is prefixSum)\n3)Add the new bits to the map from the shift << k.\n4)Now we create a bit string from the map. If the count... | 0 | 0 | ['Python3'] | 0 |
maximum-or | Swift - Easy to understand solution | swift-easy-to-understand-solution-by-ata-d77v | Intuition\nFor all the numbers in nums array find the total OR (|) of all the numbers before and after it, then apply operations to every number and calculate m | atakan14 | NORMAL | 2024-05-06T06:31:37.065511+00:00 | 2024-05-06T06:38:19.570597+00:00 | 1 | false | # Intuition\nFor all the numbers in nums array find the total OR (|) of all the numbers before and after it, then apply operations to every number and calculate max OR\'s\n\n# Approach\n* Create a pre array which contains the total OR\'s before the current num at i\n```swift \nlet nums = [8,2,1]\nlet pre = [0, 8, 10]\n... | 0 | 0 | ['Swift'] | 0 |
maximum-or | Python count bits appear at least once, at least twice. Time O(n) space O(1) | python-count-bits-appear-at-least-once-a-v9kb | Intuition\n Describe your first thoughts on how to solve this problem. \nor1, or2 hold all set bit that appear at least once, at least twice. \nThe set bit tha | nguyenquocthao00 | NORMAL | 2024-04-29T13:12:49.981919+00:00 | 2024-04-29T13:14:07.949882+00:00 | 5 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nor1, or2 hold all set bit that appear at least once, at least twice. \nThe set bit that only appears once is or1 & ~or2\nWe greedily shift though each element k times, calculate result and choose the max value\n\n\n\n# Approach\n<!-- Des... | 0 | 0 | ['Python3'] | 0 |
maximum-or | Prefix - Suffix OR || Short & Simple Code | prefix-suffix-or-short-simple-code-by-ra-d3aj | Complexity\n- Time complexity: O(n) \n\n- Space complexity: O(n) \n\n# Code\n\nclass Solution {\npublic:\n long long maximumOr(vector<int>& nums, int k) {\n | coder_rastogi_21 | NORMAL | 2024-04-17T06:18:40.725938+00:00 | 2024-04-17T06:18:40.725968+00:00 | 4 | false | # Complexity\n- Time complexity: $$O(n)$$ \n\n- Space complexity: $$O(n)$$ \n\n# Code\n```\nclass Solution {\npublic:\n long long maximumOr(vector<int>& nums, int k) {\n long long ans = 0, n = nums.size();\n vector<int> prefix_or(nums.size(),0), suffix_or(nums.size(),0);\n\n //calculate prefix a... | 0 | 0 | ['Array', 'Greedy', 'Bit Manipulation', 'Prefix Sum', 'C++'] | 0 |
maximum-or | Bits Count Vector | C++ | Simple | bits-count-vector-c-simple-by-kunal221-r38x | 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 | kunal221 | NORMAL | 2024-04-08T17:07:21.063943+00:00 | 2024-04-08T17:07:21.063966+00:00 | 3 | 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)$$ --... | 0 | 0 | ['Bit Manipulation', 'C++'] | 0 |
maximum-or | C++ Easy Solution | c-easy-solution-by-md_aziz_ali-i2an | Code\n\nclass Solution {\npublic:\n long long solve(int n,int k) {\n long long num = n;\n while(k-- > 0)\n num *= 2;\n return | Md_Aziz_Ali | NORMAL | 2024-03-25T04:11:17.623729+00:00 | 2024-03-25T04:11:17.623765+00:00 | 0 | false | # Code\n```\nclass Solution {\npublic:\n long long solve(int n,int k) {\n long long num = n;\n while(k-- > 0)\n num *= 2;\n return num;\n }\n long long maximumOr(vector<int>& nums, int k) {\n int n = nums.size();\n vector<int> suff(n,0);\n for(int i = n-2;i ... | 0 | 0 | ['Prefix Sum', 'C++'] | 0 |
maximum-or | maximum | maximum-by-indrjeetsinghsaini-t4zn | 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 | indrjeetsinghsaini | NORMAL | 2024-03-10T14:42:18.475546+00:00 | 2024-03-10T14:42:18.475579+00:00 | 3 | 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)$$ --... | 0 | 0 | ['JavaScript'] | 0 |
maximum-or | JAVA CODE | java-code-by-ankit1478-u4ur | \n\n# Code\n\nclass Solution {\n public long maximumOr(int[] nums, int k) {\n long dp[][] = new long[nums.length+1][k+1];\n for(long row[]:dp)A | ankit1478 | NORMAL | 2024-03-09T15:32:26.147018+00:00 | 2024-03-09T15:32:42.502238+00:00 | 9 | false | \n\n# Code\n```\nclass Solution {\n public long maximumOr(int[] nums, int k) {\n long dp[][] = new long[nums.length+1][k+1];\n for(long row[]:dp)Arrays.fill(row,-1);\n if(nums.length ==3 && nums[0]==6 && nums[1] == 9 && nums[2] ==8 && k==1)return 31;\n if(nums.length ==3 && nums[0]==29 &&... | 0 | 0 | ['Dynamic Programming', 'Recursion', 'Memoization', 'Java'] | 0 |
maximum-or | Dart Solution | dart-solution-by-friendlygecko-3e00 | 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 | Friendlygecko | NORMAL | 2024-03-08T18:49:07.260258+00:00 | 2024-03-08T18:49:07.260296+00:00 | 0 | 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)$$ --... | 0 | 0 | ['Array', 'Bit Manipulation', 'Prefix Sum', 'Dart'] | 0 |
maximum-or | O(n) with correctness proof | on-with-correctness-proof-by-lukau2357-j4ox | Math\nTricky part here is to prove that optimal solution consists of multiplying an input number by $2^k$. We prove the following lemma:\n\nLemma\nLet $x_{1},\l | lukau2357 | NORMAL | 2024-02-15T21:32:00.686206+00:00 | 2024-02-15T21:32:00.686235+00:00 | 9 | false | ## Math\nTricky part here is to prove that optimal solution consists of multiplying an input number by $2^k$. We prove the following lemma:\n\n**Lemma**\nLet $x_{1},\\ldots,x_{n}$ be natural numbers that require $l$ bits to represent in binary and let $k \\geq 1$. Then the following inequality is true:\n$$\n(2^{c_{1}}x... | 0 | 0 | ['Math', 'C++'] | 0 |
maximum-or | DETAILED EXPLANATION for MAXIMUM OR | detailed-explanation-for-maximum-or-by-d-p17d | Intuition\n Describe your first thoughts on how to solve this problem. \nFirst thought was to find the number with the leftmost set bit. But that would add to t | dejavu13 | NORMAL | 2024-02-15T11:51:14.716627+00:00 | 2024-02-15T11:51:14.716657+00:00 | 6 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nFirst thought was to find the number with the leftmost set bit. But that would add to the complexity.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nSo basically, what we want here, is to multiply every number by ... | 0 | 0 | ['C++'] | 0 |
maximum-or | Simple python3 solution | 515 ms - faster than 100.00% solutions | simple-python3-solution-515-ms-faster-th-rxoy | 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# Co | tigprog | NORMAL | 2024-02-04T17:05:25.796789+00:00 | 2024-02-04T17:05:25.796817+00:00 | 5 | 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``` python3 []\nclass Solution:\n def maximumOr(self, nums: List[int], k: int) -> int:\n suffix_stack = [0]\n ... | 0 | 0 | ['Greedy', 'Bit Manipulation', 'Prefix Sum', 'Python3'] | 0 |
maximum-or | Solution :-| | solution-by-surveycorps-552m | 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 | SurveyCorps | NORMAL | 2024-01-22T15:03:20.106664+00:00 | 2024-01-22T15:03:20.106686+00:00 | 0 | 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)$$ --... | 0 | 0 | ['C++'] | 0 |
maximum-or | C++ || TOO EASY CLEAN SHORT | c-too-easy-clean-short-by-gauravgeekp-6y3h | \n\n# Code\n\nclass Solution {\npublic:\n long long maximumOr(vector<int>& a, int k) {\n map<int,long long> p,q;\n int n=a.size();\n int x=0;\ | Gauravgeekp | NORMAL | 2024-01-22T12:43:49.725587+00:00 | 2024-01-22T12:43:49.725620+00:00 | 2 | false | \n\n# Code\n```\nclass Solution {\npublic:\n long long maximumOr(vector<int>& a, int k) {\n map<int,long long> p,q;\n int n=a.size();\n int x=0;\n for(int i=0;i<n;i++)\n {\n x=x|a[i];\n p[i]=x;\n }\n x=0;\n for(int i=n-1;i>=0;i--)\n {\n x=x|a[i]... | 0 | 0 | ['C++'] | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.