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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
get-equal-substrings-within-budget | **Maximizing Equal Substrings Within a Given Cost Using Sliding Window Technique** | maximizing-equal-substrings-within-a-giv-1zyw | \n# Intuition\nWhen given two strings and a cost constraint, the problem essentially boils down to finding the longest substring that can be transformed within | kazakie96 | NORMAL | 2024-05-29T06:57:24.650654+00:00 | 2024-05-29T06:57:24.650676+00:00 | 3 | false | \n# Intuition\nWhen given two strings and a cost constraint, the problem essentially boils down to finding the longest substring that can be transformed within the given cost. My first thought was to use a sliding window approach. This method is efficient for problems involving subarrays or substrings and constraints, ... | 1 | 0 | ['Java'] | 0 |
get-equal-substrings-within-budget | Easy Sliding Window Solution | easy-sliding-window-solution-by-shivamkh-rf1w | \n# Code\n\nclass Solution {\npublic:\n static int equalSubstring(string& s, string& t, int maxCost) {\n const int n=s.size();\n int l=0, r;// | ShivamKhator | NORMAL | 2024-05-29T06:00:47.923191+00:00 | 2024-05-29T06:00:47.923209+00:00 | 7 | false | \n# Code\n```\nclass Solution {\npublic:\n static int equalSubstring(string& s, string& t, int maxCost) {\n const int n=s.size();\n int l=0, r;// 2 pointers\n int cost=0, len=0;\n\n // Initialize the window by moving r while cost<=maxCost\n for (r = 0; r < n; r++) {\n co... | 1 | 0 | ['String', 'Sliding Window', 'Prefix Sum', 'C++'] | 0 |
get-equal-substrings-within-budget | Sliding window | sliding-window-by-drgavrikov-in2z | Approach\n Describe your approach to solving the problem. \nUse the classic sliding window approach to solve this problem with two pointers (left pointer and ri | drgavrikov | NORMAL | 2024-05-28T22:34:29.691886+00:00 | 2024-05-28T22:46:28.504972+00:00 | 17 | false | # Approach\n<!-- Describe your approach to solving the problem. -->\nUse the classic sliding window approach to solve this problem with two pointers (left pointer and right pointer) to find the longest valid substring. \n\nIterate through the differences in ASCII values between corresponding characters of s and t with ... | 1 | 0 | ['Sliding Window', 'Kotlin'] | 0 |
get-equal-substrings-within-budget | Kotlin. Beats 100% (150 ms). Sliding window + static "diffs" array | kotlin-beats-100-150-ms-sliding-window-s-7px3 | \n\n# Code\n\nclass Solution {\n fun equalSubstring(s: String, t: String, maxCost: Int): Int {\n for (i in 0 until s.length) {\n diffs[i] = | mobdev778 | NORMAL | 2024-05-28T21:04:19.163278+00:00 | 2024-05-28T21:04:19.163296+00:00 | 4 | false | \n\n# Code\n```\nclass Solution {\n fun equalSubstring(s: String, t: String, maxCost: Int): Int {\n for (i in 0 until s.length) {\n diffs[i] = Math.abs(s[i] - t[i])\n }\n ... | 1 | 0 | ['Kotlin'] | 0 |
get-equal-substrings-within-budget | sliding window | sliding-window-by-mr_stark-ao5p | \nclass Solution {\npublic:\n int equalSubstring(string s, string t, int mc) {\n int i = 0;\n int j = 0;\n int n = s.length();\n | mr_stark | NORMAL | 2024-05-28T19:08:22.363085+00:00 | 2024-05-28T19:08:22.363110+00:00 | 14 | false | ```\nclass Solution {\npublic:\n int equalSubstring(string s, string t, int mc) {\n int i = 0;\n int j = 0;\n int n = s.length();\n int cc= 0,res = 0;\n while(j<n)\n {\n cc += abs(s[j]-t[j]);\n while(cc>mc)\n {\n cc -= (abs(s[i... | 1 | 0 | ['C'] | 0 |
construct-the-minimum-bitwise-array-i | [Java/C++/Python] Low Bit, O(n) | javacpython-low-bit-on-by-lee215-on3s | Intuition\nans[i] OR (ans[i] + 1) == nums[i]\nans[i] and ans[i] + 1 are one odd and one even.\nnums[i] is an odd.\n\n\n# Explanation\n..0111 || (..0111 + 1) = | lee215 | NORMAL | 2024-10-12T17:29:49.389526+00:00 | 2024-10-14T03:10:02.060348+00:00 | 1,062 | false | # **Intuition**\n`ans[i] OR (ans[i] + 1) == nums[i]`\n`ans[i]` and `ans[i] + 1` are one odd and one even.\n`nums[i]` is an odd.\n<br>\n\n# **Explanation**\n`..0111 || (..0111 + 1) = ..1111`\nThe effect is that change the rightmost 0 to 1.\n\nFor each `a` in array `A`,\nfind the rightmost 0,\nand set the next bit from ... | 14 | 0 | ['C', 'Python', 'Java'] | 2 |
construct-the-minimum-bitwise-array-i | Python3 || 11 lines, just odd numbers || T/S: 99% / 25% | python3-11-lines-just-odd-numbers-ts-99-jog3f | Here\'s the intuition:\n\nThe prime number condition is a red herring. The real condition is the elements of nums are odd integers (excepting of course, 2). Odd | Spaulding_ | NORMAL | 2024-10-12T17:23:49.583340+00:00 | 2024-10-16T21:37:11.677326+00:00 | 518 | false | Here\'s the intuition:\n\nThe *prime number* condition is a *red herring*. The real condition is the elements of `nums` are odd integers (excepting of course, 2). Odd numbers are either *4 mod 1* or *4 mod 3*. The *4 mod 1* case becomes trivial after analyzing some examples. The *4 mod 3* case requires a bit more inves... | 13 | 0 | ['C++', 'Java', 'Python3'] | 0 |
construct-the-minimum-bitwise-array-i | Explained - Bit wise manipulation || Very simple and easy understand | explained-bit-wise-manipulation-very-sim-2g2q | \n# Intuition \n- By analysing few cases I observed following:\n - as all are prime except 2, all numbers are odd ( so the last bit is set)\n - as all numbers | kreakEmp | NORMAL | 2024-10-12T16:04:50.193936+00:00 | 2024-10-12T16:04:50.193973+00:00 | 1,854 | false | \n# Intuition \n- By analysing few cases I observed following:\n - as all are prime except 2, all numbers are odd ( so the last bit is set)\n - as all numbers are odd => trivial ans is n-1. Where n-1 one has last bit set to zero and (n-1) | n will be always eqaul to n\n - Now we need to optimise further to find a s... | 12 | 0 | ['C++'] | 2 |
construct-the-minimum-bitwise-array-i | Easy Approach for Beginners | easy-approach-for-beginners-by-siddhuuse-wflm | Intuition \n Describe your first thoughts on how to solve this problem. \nGiven a list of numbers, the goal is to find the smallest integer \( j \) such that | siddhuuse | NORMAL | 2024-10-12T17:08:50.191086+00:00 | 2024-10-12T17:08:50.191114+00:00 | 451 | false | # Intuition \n<!-- Describe your first thoughts on how to solve this problem. --> \nGiven a list of numbers, the goal is to find the smallest integer \\( j \\) such that \\( j | (j + 1) = i \\) for each \\( i \\) in the input list. If no such \\( j \\) exists, we return -1 for that element. The bitwise OR operation b... | 9 | 0 | ['Array', 'Bit Manipulation', 'Python3'] | 1 |
construct-the-minimum-bitwise-array-i | 💖 [EASY] INTUITION & EXPLANATION | easy-intuition-explanation-by-ramitgangw-np5k | \n\n# \uD83D\uDC93**_PLEASE CONSIDER UPVOTING_**\uD83D\uDC93\n\n \n\n\n# \u2B50 Intuition\nTo construct the minimum bitwise array ans, we need to find the small | ramitgangwar | NORMAL | 2024-10-12T16:06:41.526945+00:00 | 2024-10-12T16:06:41.526979+00:00 | 533 | false | <div align="center">\n\n# \uD83D\uDC93**_PLEASE CONSIDER UPVOTING_**\uD83D\uDC93\n\n</div>\n\n***\n# \u2B50 Intuition\nTo construct the minimum bitwise array `ans`, we need to find the smallest integer `ans[i]` such that the bitwise OR of `ans[i]` and `ans[i] + 1` equals `nums[i]`. Since `nums[i]` is guaranteed to be a... | 6 | 0 | ['Java'] | 1 |
construct-the-minimum-bitwise-array-i | Simple Java || C++ Code ☠️ | simple-java-c-code-by-abhinandannaik1717-tzaj | Code\njava []\nclass Solution {\n public int[] minBitwiseArray(List<Integer> nums) {\n int n = nums.size();\n int[] ans = new int[n];\n | abhinandannaik1717 | NORMAL | 2024-10-14T13:02:41.540525+00:00 | 2024-10-14T13:02:41.540550+00:00 | 217 | false | # Code\n```java []\nclass Solution {\n public int[] minBitwiseArray(List<Integer> nums) {\n int n = nums.size();\n int[] ans = new int[n];\n for(int i=0;i<n;i++){\n int a = nums.get(i);\n for(int j=0;j<a;j++){\n if((j | (j+1)) == a){\n ans[... | 5 | 0 | ['C++', 'Java'] | 0 |
construct-the-minimum-bitwise-array-i | [Python3] Brute-Force -> Greedy - Detailed Solution | python3-brute-force-greedy-detailed-solu-y1a8 | Intuition\n Describe your first thoughts on how to solve this problem. \n- Using pen and draw some examples and recognized the pattern\n\n\nInput | Answer | Inp | dolong2110 | NORMAL | 2024-10-12T16:01:58.622170+00:00 | 2024-10-12T16:52:48.745616+00:00 | 193 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n- Using pen and draw some examples and recognized the pattern\n\n```\nInput | Answer | Input | Answer\n-------------------------------\n2 -1 10\n3 1 11 1\n5 4 101 100\n7 3... | 5 | 0 | ['Greedy', 'Bit Manipulation', 'Python3'] | 0 |
construct-the-minimum-bitwise-array-i | 💡Efficient Java Solution | O(n) time complexity | 100% Beat 💡 | efficient-java-solution-on-time-complexi-0yw6 | Intuition
Prime Numbers:
The list nums contains prime numbers. All primes except 2 are odd numbers, and the only even prime number is 2.
This observation is cr | princevanani9 | NORMAL | 2024-12-30T09:42:43.066929+00:00 | 2024-12-30T09:42:43.066929+00:00 | 150 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
1. Prime Numbers:
- The list nums contains prime numbers. All primes except 2 are odd numbers, and the only even prime number is 2.
- This observation is critical because prime numbers, when written in binary, follow certain patterns.
2. ... | 4 | 0 | ['Array', 'Bit Manipulation', 'Java'] | 0 |
construct-the-minimum-bitwise-array-i | Java Clean solution | 100% Beat | java-clean-solution-100-beat-by-shree_go-xmjt | Complexity\n- Time complexity:O(n^2)\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 | Shree_Govind_Jee | NORMAL | 2024-10-12T16:03:54.540597+00:00 | 2024-10-12T16:03:54.540619+00:00 | 347 | false | # Complexity\n- Time complexity:$$O(n^2)$$\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 public int[] minBitwiseArray(List<Integer> nums) {\n int n = nums.size();\n ... | 3 | 0 | ['Array', 'Math', 'Bit Manipulation', 'Bitmask', 'Java'] | 0 |
construct-the-minimum-bitwise-array-i | Easy linear O(n*31) solution ----> | easy-linear-on31-solution-by-be_fighter-v23y | Understanding the Problem:\n1. For each number in the array nums, you want to generate a new number that is the "minimum" possible based on certain bitwise oper | be_fighter | NORMAL | 2024-10-12T17:17:50.525481+00:00 | 2024-10-12T17:17:50.525515+00:00 | 105 | false | # Understanding the Problem:\n1. For each number in the array nums, you want to generate a new number that is the "minimum" possible based on certain bitwise operations.\n\n2. The exact property you\'re trying to maintain here is that if you modify a bit, you want the new number (newnum) to still be closely related to ... | 2 | 0 | ['Array', 'Bit Manipulation', 'Bitmask', 'C++', 'Java', 'Python3', 'JavaScript'] | 1 |
construct-the-minimum-bitwise-array-i | Simple | Beats 100% | simple-beats-100-by-lokeshwar777-4o39 | Code\npython3 []\nclass Solution:\n def minBitwiseArray(self, nums: List[int]) -> List[int]:\n res = []\n\n for num in nums:\n for i | lokeshwar777 | NORMAL | 2024-10-12T16:07:27.894191+00:00 | 2024-10-12T16:07:27.894214+00:00 | 139 | false | # Code\n```python3 []\nclass Solution:\n def minBitwiseArray(self, nums: List[int]) -> List[int]:\n res = []\n\n for num in nums:\n for i in range(num):\n if i | (i+1) == num:\n res.append(i)\n break\n else:\n res... | 2 | 0 | ['Python3'] | 1 |
construct-the-minimum-bitwise-array-i | brute force | brute-force-by-_dharamvir-cck0 | 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 | _dharamvir__ | NORMAL | 2024-10-12T16:02:00.432870+00:00 | 2024-10-12T16:02:00.432907+00:00 | 327 | 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*1000)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(n)\n<!-- Add your space complexity here, e.g... | 2 | 0 | ['Array', 'C++'] | 0 |
construct-the-minimum-bitwise-array-i | C++ brute force, beats 100% time | c-brute-force-beats-100-by-amithm7-nq5f | Intuition & ApproachCheck for a number k = 0 to nums[i] - 1 with (k | k+1) == nums[i]. Exit loop on match since we want smallest k.Complexity
Time complexity: | amithm7 | NORMAL | 2025-02-01T06:27:07.915042+00:00 | 2025-02-01T06:28:31.138864+00:00 | 44 | false | # Intuition & Approach
Check for a number `k` = `0` to `nums[i] - 1` with `(k | k+1) == nums[i]`. Exit loop on match since we want smallest `k`.
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
```... | 1 | 1 | ['C++'] | 0 |
construct-the-minimum-bitwise-array-i | C++ in-place 100% | c-in-place-100-by-michelusa-9fj5 | \ncpp []\nclass Solution {\npublic:\n vector<int> minBitwiseArray(vector<int> nums) const {\n \n for (int i = 0; i != nums.size(); ++i) {\n | michelusa | NORMAL | 2024-11-29T16:26:17.906077+00:00 | 2024-11-29T16:26:17.906112+00:00 | 28 | false | \n```cpp []\nclass Solution {\npublic:\n vector<int> minBitwiseArray(vector<int> nums) const {\n \n for (int i = 0; i != nums.size(); ++i) {\n int target = exchange(nums[i], -1); \n for (int val = 1; val != target; ++val) {\n if ((val | (val+ 1)) == targe... | 1 | 0 | ['C++'] | 0 |
construct-the-minimum-bitwise-array-i | C++ in-place | c-in-place-by-michelusa-twjc | 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 | michelusa | NORMAL | 2024-11-29T16:15:32.428056+00:00 | 2024-11-29T16:15:32.428091+00:00 | 22 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 1 | 0 | ['C++'] | 0 |
construct-the-minimum-bitwise-array-i | Finding the Largest Integer 𝑖 i Such That ( 𝑖 ∣ ( 𝑖 + 1 ) ) = 𝑎 (i∣(i+1))=a | finding-the-largest-integer-i-i-such-tha-pum8 | Intuition\nWe are given a list of integers, and for each integer, we need to find a value \( i \) such that when you perform the bitwise OR operation between \( | 204g1a0551 | NORMAL | 2024-11-13T10:19:14.455824+00:00 | 2024-11-13T10:19:14.455854+00:00 | 19 | false | ### Intuition\nWe are given a list of integers, and for each integer, we need to find a value \\( i \\) such that when you perform the bitwise OR operation between \\( i \\) and \\( i+1 \\), the result is equal to the original integer. The goal is to compute this value \\( i \\) for each element of the input list and r... | 1 | 0 | ['Java'] | 0 |
construct-the-minimum-bitwise-array-i | Clever Bitlogic with Rust | clever-bitlogic-with-rust-by-chrispls-xt2i | Intuition\nThe core idea here is to use the "+ 1" to cascade carry bits and restore a the highest bit of the original number it can. \n\n# Approach\n\nI\'ve don | chrispls | NORMAL | 2024-10-20T21:16:51.768592+00:00 | 2024-10-20T21:16:51.768621+00:00 | 9 | false | # Intuition\nThe core idea here is to use the "+ 1" to cascade carry bits and restore a the highest bit of the original number it can. \n\n# Approach\n\nI\'ve done my best to detail the workings in the code + debug logging.\nFirst off, if `num` is even, there\'s no way to encode it as `x | (x + 1)`. \n- If `x` is even,... | 1 | 0 | ['Bit Manipulation', 'Rust'] | 0 |
construct-the-minimum-bitwise-array-i | 💡✅🔥 Bitwise operations with detailed explanation🔥 C++ Simple Solution 🔥 🧠Optimized ✅ | bitwise-operations-with-detailed-explana-jnko | \n\n## Problem Overview\n\nThe goal of this problem is to find a value x for each number in the array nums such that:\n\n1. \( x \) is a non-negative integer le | franesh | NORMAL | 2024-10-15T17:56:50.039621+00:00 | 2024-10-15T17:56:50.039659+00:00 | 36 | false | \n\n## Problem Overview\n\nThe goal of this problem is to find a value `x` for each number in the array `nums` such that:\n\n1. \\( x \\) is a non-negative integer less than the current number \\( \\text{num} \\).\n2. \\( x \\) should satisfy the equation \\( x \\text{ OR } (x + 1) = \\text{num} \\), where "OR" represe... | 1 | 0 | ['Array', 'Bit Manipulation', 'C++'] | 0 |
construct-the-minimum-bitwise-array-i | Simple C sol, Beats 100% :) | simple-c-sol-beats-100-by-user0490hi-xm65 | 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 | user0490hI | NORMAL | 2024-10-14T13:50:43.631013+00:00 | 2024-10-14T13:50:43.631048+00:00 | 57 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 1 | 0 | ['C'] | 0 |
construct-the-minimum-bitwise-array-i | easy solution | easy-solution-by-leet1101-85t7 | Intuition\nWe need to find an integer ans[i] such that the bitwise OR of ans[i] and ans[i] + 1 is equal to nums[i] for each prime number in the input array nums | leet1101 | NORMAL | 2024-10-12T17:26:57.671750+00:00 | 2024-10-12T17:26:57.671768+00:00 | 159 | false | # Intuition\nWe need to find an integer `ans[i]` such that the bitwise OR of `ans[i]` and `ans[i] + 1` is equal to `nums[i]` for each prime number in the input array `nums`. The challenge is to minimize the value of `ans[i]` while ensuring this condition holds. If no such value of `ans[i]` exists, we return `-1`.\n\n# ... | 1 | 0 | ['C++'] | 0 |
construct-the-minimum-bitwise-array-i | 💡✅🔥 Bitwise operations with detailed explanation | bitwise-operations-with-detailed-explana-9edp | Intuition\nObservations:\n- all prime numbers are odd (except 10_2), so numbers will always be like ...0111 or 111\n- simpliest answer is just num - 1, but we w | jekatigr | NORMAL | 2024-10-12T16:51:15.503147+00:00 | 2024-10-12T16:51:15.503184+00:00 | 58 | false | # Intuition\nObservations:\n- all prime numbers are odd (except $$10_2$$), so numbers will always be like `...0111` or `111`\n- simpliest answer is just `num - 1`, but we want to minimize it\n- it\'s easy to notice how to find an answer for a number with ones only (like `1111`). We just need to take a number without le... | 1 | 0 | ['Array', 'Math', 'Bit Manipulation', 'JavaScript'] | 0 |
construct-the-minimum-bitwise-array-i | Easy Java Solution || Beats 100% || | easy-java-solution-beats-100-by-gaganurs-6rei | \n\n# Code\njava []\nclass Solution {\n public int[] minBitwiseArray(List<Integer> nums) {\n int []output=new int[nums.size()];\n for(int i=0;i< | gaganursmg | NORMAL | 2024-10-12T16:03:37.361549+00:00 | 2024-10-12T16:03:37.361573+00:00 | 67 | false | \n\n# Code\n```java []\nclass Solution {\n public int[] minBitwiseArray(List<Integer> nums) {\n int []output=new int[nums.size()];\n for(int i=0;i<nums.size();i++){\n int num=nums.get(i);\n int sum=-1;\n int a=0;\n while(a<num){\n if((a | a+1)==nums.get(i)){\n ... | 1 | 0 | ['Bit Manipulation', 'Java'] | 0 |
construct-the-minimum-bitwise-array-i | simple | simple-by-ryuji-2a1b | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | ryuji | NORMAL | 2025-03-30T21:19:17.695089+00:00 | 2025-03-30T21:19:17.695089+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 | ['Rust'] | 0 |
construct-the-minimum-bitwise-array-i | Simple Swift Solution | simple-swift-solution-by-felisviridis-hwdo | Code | Felisviridis | NORMAL | 2025-03-27T09:34:22.899176+00:00 | 2025-03-27T09:34:22.899176+00:00 | 1 | false | 
# Code
```swift []
class Solution {
func minBitwiseArray(_ nums: [Int]) -> [Int] {
var result = [Int]()
for num in nums {
var found = false
... | 0 | 0 | ['Swift'] | 0 |
construct-the-minimum-bitwise-array-i | Java&JS&TS Solution (JW) | javajsts-solution-jw-by-specter01wj-c4yw | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | specter01wj | NORMAL | 2025-03-26T19:21:46.551987+00:00 | 2025-03-26T19:21:46.551987+00:00 | 2 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
`... | 0 | 0 | ['Array', 'Bit Manipulation', 'Java', 'TypeScript', 'JavaScript'] | 0 |
construct-the-minimum-bitwise-array-i | C++ simple concept ,complexity - O(n^2), bit , beats 100% | c-simple-concept-complexity-on2-bit-beat-9crq | IntuitionApproach
starting inner loop from the nums[i]/2 because analysing showing that not any j is less than nums[i]/2 value except nums[i]==2
Complexity
Time | mihirbaraiya | NORMAL | 2025-03-14T06:06:40.232868+00:00 | 2025-03-14T06:06:40.232868+00:00 | 3 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->
* starting inner loop from the num... | 0 | 0 | ['Array', 'C++'] | 0 |
construct-the-minimum-bitwise-array-i | Easy to understand solution in Java. | easy-to-understand-solution-in-java-by-k-a5c5 | Complexity
Time complexity:
O(n * max_num)
(where max_num is the maximum value in the list nums).
Space complexity:
O(n)
Code | Khamdam | NORMAL | 2025-03-10T06:34:35.353090+00:00 | 2025-03-10T06:34:35.353090+00:00 | 3 | false | # Complexity
- Time complexity:
O(n * max_num)
*(where max_num is the maximum value in the list nums)*.
- Space complexity:
O(n)
# Code
```java []
class Solution {
public int[] minBitwiseArray(List<Integer> nums) {
int n = nums.size();
int[] ans = new int[n];
for (int i = 0; i < n; i++) ... | 0 | 0 | ['Array', 'Bit Manipulation', 'Java'] | 0 |
construct-the-minimum-bitwise-array-i | Iterative Bitwise Search | Dart Solution | Time O(n · m) | Space O(n) | iterative-bitwise-search-dart-solution-t-4rfz | ApproachThe solution processes each element in the input array and, for each element, finds the smallest candidate integer that satisfies a specific bitwise pro | user4343mG | NORMAL | 2025-03-03T05:54:18.933630+00:00 | 2025-03-03T05:54:18.933630+00:00 | 2 | false | ## Approach
The solution processes each element in the input array and, for each element, finds the smallest candidate integer that satisfies a specific bitwise property:
1. **Iterate Over the Input Array**:
For every number in the list, the algorithm attempts to find the smallest integer `j` such that the bitwise... | 0 | 0 | ['Dart'] | 0 |
construct-the-minimum-bitwise-array-i | Simple pattern based O(N) solution. Brute force is not needed. | simple-pattern-based-on-solution-brute-f-wwbu | IntuitionThe pattern is as follows:
'2' is the only prime number and hence, the result is -1
All other prime numbers apart from 2 are odd numbers i.e the lowest | night1coder | NORMAL | 2025-02-22T09:49:00.748558+00:00 | 2025-02-22T09:51:03.252736+00:00 | 3 | false | # Intuition
The pattern is as follows:
1. '2' is the only prime number and hence, the result is -1
2. All other prime numbers apart from 2 are odd numbers i.e the lowest bit is set.
3. The trivial ans is (num-1), but the question says to find the lowest possible answer.
4. Hence, we need to find the lowest one bit af... | 0 | 0 | ['Java'] | 0 |
construct-the-minimum-bitwise-array-i | kFor=cache(lambda v:k) | kforcachelambda-vk-by-qulinxao-x4gz | null | qulinxao | NORMAL | 2025-02-20T06:07:50.088605+00:00 | 2025-02-20T06:07:50.088605+00:00 | 1 | false | ```python3 []
class Solution:
def minBitwiseArray(self, nums: List[int]) -> List[int]:
kFor=cache(lambda v:k)
k=-1;kFor(2)
for k in range(max(nums)):kFor(k|(k+1))
return [kFor(v)for v in nums]
``` | 0 | 0 | ['Python3'] | 0 |
construct-the-minimum-bitwise-array-i | Pre-compute in the constructor | pre-compute-in-the-constructor-by-evgeny-6a1m | Code | evgenysh | NORMAL | 2025-02-09T16:16:01.729595+00:00 | 2025-02-09T16:16:01.729595+00:00 | 4 | false | # Code
```python3 []
class Solution:
def __init__(self, limit=1000):
self.min_or_input = dict()
# precompute the min bitwise inputs
for n in range(limit + 1):
val = n | (n + 1)
if val not in self.min_or_input:
self.min_or_input[val] = n
def minBi... | 0 | 0 | ['Python3'] | 1 |
construct-the-minimum-bitwise-array-i | Easy Approach for Beginners 2.0 | easy-approach-for-beginners-20-by-vbarys-35e3 | IntuitionLets develop ideas from https://leetcode.com/problems/construct-the-minimum-bitwise-array-i/solutions/5904063/easy-approach-for-beginners/Thanks to @si | vbaryshev | NORMAL | 2025-02-06T09:19:03.665998+00:00 | 2025-02-06T09:20:11.077683+00:00 | 10 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
Lets develop ideas from https://leetcode.com/problems/construct-the-minimum-bitwise-array-i/solutions/5904063/easy-approach-for-beginners/
Thanks to @siddhuuse (https://leetcode.com/u/siddhuuse/)
In a little clearer way, because flat is b... | 0 | 0 | ['Python3'] | 0 |
construct-the-minimum-bitwise-array-i | BEATS 100% || C++ || EASY | beats-100-c-easy-by-sakshishah11-p7u1 | Complexity
Time complexity: O(N^2)
Space complexity: O(1)
Code | SakshiShah11 | NORMAL | 2025-02-03T10:44:47.857365+00:00 | 2025-02-03T10:44:47.857365+00:00 | 6 | false |
# Complexity
- Time complexity: O(N^2)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity: O(1)
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
```cpp []
class Solution {
public:
vector<int> minBitwiseArray(vector<int>& nums) {
int n=nums.size();
vector<int> a... | 0 | 0 | ['C++'] | 0 |
construct-the-minimum-bitwise-array-i | [C++] Simple Solution | c-simple-solution-by-samuel3shin-2ufl | Code | Samuel3Shin | NORMAL | 2025-01-30T16:13:54.060449+00:00 | 2025-01-30T16:13:54.060449+00:00 | 4 | false | # Code
```cpp []
class Solution {
public:
vector<int> minBitwiseArray(vector<int>& A) {
int N = A.size();
vector<int> ans(N, -1);
for(int i=0; i<N; i++) {
for(int j=0; j<=A[i]; j++) {
if((j|(j+1)) == A[i]) {
ans[i] = j;
bre... | 0 | 0 | ['C++'] | 0 |
construct-the-minimum-bitwise-array-i | The best solution!!! without native methods... | the-best-solution-without-native-methods-oae3 | IntuitionThe problem requires finding the smallest possible (ans[i]) such that ((ans[i] | (ans[i] + 1)) = nums[i]). If no such (ans[i]) exists, it should return | javid99999 | NORMAL | 2025-01-27T19:25:17.669262+00:00 | 2025-01-27T19:25:17.669262+00:00 | 4 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
The problem requires finding the smallest possible \(ans[i]\) such that \((ans[i] | (ans[i] + 1)) = nums[i]\). If no such \(ans[i]\) exists, it should return \(-1\). The key insight is that for each \(nums[i]\), we can iterate through poten... | 0 | 0 | ['PHP'] | 0 |
construct-the-minimum-bitwise-array-i | one pass bitwise. | one-pass-bitwise-by-rishiinsane-e7aw | IntuitionApproachComplexity
Time complexity:
O(n)
Space complexity:
O(n)
Code | RishiINSANE | NORMAL | 2025-01-26T09:41:47.244906+00:00 | 2025-01-26T09:41:47.244906+00:00 | 3 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
O(n)
- Space complexity:
O(n)
# Code
```cpp []
class Solution {
public:
vector<int> minBitwiseArray(vector<int>& nums) {
int ... | 0 | 0 | ['C++'] | 0 |
construct-the-minimum-bitwise-array-i | Elixir - Bit manipulation | elixir-bit-manipulation-by-lykos_unleash-aezz | Complexity
Time complexity:
O(n)
Space complexity:
O(n)
Code | Lykos_unleashed | NORMAL | 2025-01-21T03:24:00.857130+00:00 | 2025-01-21T03:24:00.857130+00:00 | 4 | false | # Complexity
- Time complexity:
O(n)
- Space complexity:
O(n)
# Code
```elixir []
defmodule Solution do
@spec min_bitwise_array(nums :: [integer]) :: [integer]
def min_bitwise_array(nums) do
for n <- nums do
cond do
n == 2 -> -1
Bitwise.band(n, n + 1) == 0 -> remove_msb(n)
true -... | 0 | 0 | ['Elixir'] | 0 |
construct-the-minimum-bitwise-array-i | Easiest soln u will ever find | easiest-soln-u-will-ever-find-by-mamthan-tmv3 | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | mamthanagaraju1 | NORMAL | 2025-01-15T07:39:05.582413+00:00 | 2025-01-15T07:39:05.582413+00:00 | 5 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- 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 |
construct-the-minimum-bitwise-array-i | Simple C implement | simple-c-implement-by-ggandrew1218-iqi5 | Code | ggandrew1218 | NORMAL | 2025-01-13T13:02:03.008249+00:00 | 2025-01-13T13:02:03.008249+00:00 | 21 | false |
# Code
```c []
/**
* Note: The returned array must be malloced, assume caller calls free().
*/
int* minBitwiseArray(int* nums, int numsSize, int* returnSize) {
int* ans = malloc(sizeof(int) * numsSize);
for(int i = 0; i < numsSize;i++)
{
//printf("Num : %d\n", nums[i]);
if( ((nums[i... | 0 | 0 | ['C'] | 0 |
construct-the-minimum-bitwise-array-i | Easy to understand | easy-to-understand-by-vedantkhapre-kd7a | IntuitionWe need to find the smallest integer x such that x | (x + 1) equals the prime number at each index of the array. If no such x exists, we return -1Appro | vedantkhapre | NORMAL | 2025-01-13T07:01:52.089118+00:00 | 2025-01-13T07:01:52.089118+00:00 | 4 | false | # Intuition
We need to find the smallest integer `x` such that `x | (x + 1)` equals the prime number at each index of the array. If no such `x` exists, we return `-1`
---
# **Approach**
1. Initialize an answer array `ans` with `-1` (because the default answer is `-1` if no valid `x` is found).
2. Loop through each... | 0 | 0 | ['C++'] | 0 |
construct-the-minimum-bitwise-array-i | C++ 0 ms | c-0-ms-by-eridanoy-fvsa | IntuitionApproach2 -> -1
other -> replace the one before the first zero with zeroComplexity
Time complexity:
Space complexity:
Code | eridanoy | NORMAL | 2025-01-11T14:28:59.769223+00:00 | 2025-01-11T14:28:59.769223+00:00 | 5 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
2 -> -1
other -> replace the one before the first zero with zero
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 0 | 0 | ['C++'] | 0 |
construct-the-minimum-bitwise-array-i | ☑️ Golang solution beats 100% | golang-solution-beats-100-by-codemonkey8-v2q6 | Code | CodeMonkey80s | NORMAL | 2025-01-11T03:44:02.552304+00:00 | 2025-01-11T03:44:02.552304+00:00 | 8 | false | # Code
```golang []
func minBitwiseArray(nums []int) []int {
find := func(n int) int {
for i := 0; i < n; i++ {
v := i | (i + 1)
if n == v {
return i
}
}
return -1
}
res := make([]int, len(nums))
for i, num := range nums {
res[i] = find(num)
}
return res
}
``` | 0 | 0 | ['Go'] | 0 |
construct-the-minimum-bitwise-array-i | 3314. Construct the Minimum Bitwise Array I | 3314-construct-the-minimum-bitwise-array-aida | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | G8xd0QPqTy | NORMAL | 2025-01-08T08:15:40.198973+00:00 | 2025-01-08T08:15:40.198973+00:00 | 8 | 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 |
construct-the-minimum-bitwise-array-i | One Liner | one-liner-by-khaled-alomari-dlnb | Complexity
Time complexity:
O(n)
Space complexity:
O(1)
Code | khaled-alomari | NORMAL | 2024-12-30T20:50:52.212573+00:00 | 2024-12-30T20:50:52.212573+00:00 | 18 | false | # Complexity
- Time complexity:
$$O(n)$$
- Space complexity:
$$O(1)$$
# Code
```javascript []
const minBitwiseArray = nums => nums.map(v => v === 2 ? -1 : (((-v - 2) ^ v) / 4) + v);
```
```typescript []
const minBitwiseArray = (nums: number[]) => nums.map((v) => v === 2 ? -1 : (((-v - 2) ^ v) / 4) + v);
``` | 0 | 0 | ['Math', 'Bit Manipulation', 'Bitmask', 'TypeScript', 'JavaScript'] | 0 |
construct-the-minimum-bitwise-array-i | BITWISE BEHAVIOUR (100%) java | bitwise-behaviour-100-java-by-prachikuma-77x0 | IntuitionConsider the binary number behaviour for a num to satisfy { ans[i] OR ans[i] + 1 = nums[i] }
CASE 1
nums[i] % 4 == 1 ie ending 01 eg 5,9,13,.. they al | PrachiKumari | NORMAL | 2024-12-30T06:40:39.587505+00:00 | 2024-12-30T06:40:39.587505+00:00 | 8 | false | # Intuition
Consider the binary number behaviour for a num to satisfy { ans[i] OR ans[i] + 1 = nums[i] }
***CASE 1***
- nums[i] % 4 == 1 ie ending 01 eg 5,9,13,.. they all ends
& for all of them ans = nums[i]-1 , eg nums[i] = 9, then smallest possible ans = 8 (8 OR (8+1) == 9)
***CASE 2***
- nums[i] % 4 ==3 ie ending... | 0 | 0 | ['Bit Manipulation', 'Java'] | 0 |
construct-the-minimum-bitwise-array-i | Easy Java Solution | easy-java-solution-by-abhishekji66-zao2 | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | abhishekji66 | NORMAL | 2024-12-27T10:07:24.990200+00:00 | 2024-12-27T10:07:24.990200+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 | ['Java'] | 0 |
construct-the-minimum-bitwise-array-i | Worst solution ever (Must see) | worst-solution-ever-must-see-by-devansh_-wr79 | IntuitionApproachComplexity
Time complexity:O(n2)
Space complexity:O(1)
Code | devansh_1703 | NORMAL | 2024-12-24T16:38:57.338467+00:00 | 2024-12-24T16:38:57.338467+00:00 | 3 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:$$O(n^2)$$
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:$$O(1)$$
<!-- Add your space complexity here, e.g. $$O(... | 0 | 0 | ['Java'] | 0 |
construct-the-minimum-bitwise-array-i | Optimal C++ Solution Beats 100% | optimal-c-solution-beats-100-by-dakshg-2ny7 | Code\ncpp []\nclass Solution {\npublic:\n vector<int> minBitwiseArray(vector<int> &nums) {\n int n = nums.size();\n vector<int> ans(n);\n\n | dakshg | NORMAL | 2024-12-05T03:30:15.643843+00:00 | 2024-12-05T03:30:15.643879+00:00 | 12 | false | # Code\n```cpp []\nclass Solution {\npublic:\n vector<int> minBitwiseArray(vector<int> &nums) {\n int n = nums.size();\n vector<int> ans(n);\n\n for(int i = 0; i < n; ++i) {\n if(nums[i] == 2) {\n ans[i] = -1;\n continue;\n }\n\n int... | 0 | 0 | ['C++'] | 0 |
construct-the-minimum-bitwise-array-i | Beats 100% using bit manipulation | beats-100-using-bit-manipulation-by-gopi-a8m1 | 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 | gopigaurav | NORMAL | 2024-12-01T09:57:33.463434+00:00 | 2024-12-01T09:57:33.463469+00:00 | 10 | 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 | ['Python3'] | 0 |
construct-the-minimum-bitwise-array-i | Rust/Python. Real linear solution with full explanation | rustpython-real-linear-solution-with-ful-5mqg | Intuition\n\nFirst we need to understand that the question asks to solve equation:\n\nx OR (x + 1) = y\n\nfor x. Here they have a strange requirement of y being | salvadordali | NORMAL | 2024-11-26T08:06:31.363891+00:00 | 2024-11-26T08:06:39.739515+00:00 | 6 | false | # Intuition\n\nFirst we need to understand that the question asks to solve equation:\n\n`x OR (x + 1) = y`\n\nfor `x`. Here they have a strange requirement of `y` being prime, but we later we will see that it is irrelevant. On top of this the `x` should be as small as possible.\n\n\nLets look at some number `1011100111... | 0 | 0 | ['Python3', 'Rust'] | 0 |
construct-the-minimum-bitwise-array-i | Easy Java Solution | easy-java-solution-by-mayankbisht8630-max3 | 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 | MayankBisht8630 | NORMAL | 2024-11-23T16:25:56.545924+00:00 | 2024-11-23T16:25:56.545949+00:00 | 7 | 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 | ['Java'] | 0 |
construct-the-minimum-bitwise-array-i | 🟢🔴🟢 Beats 100.00%👏 Easiest Solution 🟢🔴🟢 | beats-10000-easiest-solution-by-develope-39ib | \nclass Solution {\n List<int> minBitwiseArray(List<int> nums) {\n\n List<int> ans = [];\n for(int i = 0; i < nums.length; i++){\n int prime = -1; | developerSajib88 | NORMAL | 2024-11-13T06:33:09.665383+00:00 | 2024-11-13T06:33:09.665411+00:00 | 25 | false | ```\nclass Solution {\n List<int> minBitwiseArray(List<int> nums) {\n\n List<int> ans = [];\n for(int i = 0; i < nums.length; i++){\n int prime = -1; \n for(int j = 1; j < nums[i]; j++){\n if(j | (j + 1) == nums[i]){\n prime = j;\n break;\n }\n }\n ans.add... | 0 | 0 | ['C', 'Python', 'C++', 'Java', 'JavaScript', 'C#', 'Dart'] | 0 |
construct-the-minimum-bitwise-array-i | Swift💯 | swift-by-upvotethispls-8xxe | Optimized Brute Force Search (accepted answer)\nOR-ing by (n+1) will never yield an even result, so if n is even (n&1==1), return -1. Otherwise brute force sear | UpvoteThisPls | NORMAL | 2024-11-13T00:09:36.171269+00:00 | 2024-11-13T00:09:36.171303+00:00 | 5 | false | **Optimized Brute Force Search (accepted answer)**\nOR-ing by (n+1) will never yield an even result, so if `n` is even (`n&1==1`), return -1. Otherwise brute force search from `n/2` on to find the smallest possible result. \n```\nclass Solution {\n func minBitwiseArray(_ nums: [Int]) -> [Int] {\n nums.map{ n i... | 0 | 0 | ['Swift'] | 0 |
construct-the-minimum-bitwise-array-i | Easy to UnderStand Beginner Friendly | easy-to-understand-beginner-friendly-by-5e06x | To address this problem, here\u2019s the breakdown:\n\n# Intuition\nThe goal is to transform each element of the array v by minimizing its binary representation | tinku_tries | NORMAL | 2024-11-11T09:51:29.239621+00:00 | 2024-11-11T09:51:29.239657+00:00 | 4 | false | To address this problem, here\u2019s the breakdown:\n\n# Intuition\nThe goal is to transform each element of the array `v` by minimizing its binary representation. For each element `v[i]`, if it is odd, we attempt to adjust it such that the resulting value retains as few high-value bits as possible while being slightly... | 0 | 0 | ['Array', 'Bit Manipulation', 'C++'] | 0 |
construct-the-minimum-bitwise-array-i | Short and Easy Solution ✅✅ | short-and-easy-solution-by-poojakapri252-y3av | 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 | poojakapri2529 | NORMAL | 2024-11-10T16:56:36.436376+00:00 | 2024-11-10T16:56:36.436412+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 | ['C++'] | 0 |
construct-the-minimum-bitwise-array-i | Construct the Minimum bitwise array - python3 solution | construct-the-minimum-bitwise-array-pyth-y8hi | 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 | ChaithraDee | NORMAL | 2024-11-10T14:54:25.382917+00:00 | 2024-11-10T14:54:25.382940+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 | ['Python3'] | 0 |
construct-the-minimum-bitwise-array-i | C# brute force | c-brute-force-by-dmitriy-maksimov-v63c | Complexity\n- Time complexity: O(n \times 2^m)\n- Space complexity: O(n)\n\n# Code\ncsharp []\npublic class Solution\n{\n public int[] MinBitwiseArray(IList< | dmitriy-maksimov | NORMAL | 2024-11-10T08:06:19.051206+00:00 | 2024-11-10T08:06:19.051240+00:00 | 6 | false | # Complexity\n- Time complexity: $$O(n \\times 2^m)$$\n- Space complexity: $$O(n)$$\n\n# Code\n```csharp []\npublic class Solution\n{\n public int[] MinBitwiseArray(IList<int> nums)\n {\n var result = Enumerable.Repeat(-1, nums.Count).ToArray();\n\n for (var i = 0; i < nums.Count; i++)\n {\n ... | 0 | 0 | ['C#'] | 0 |
construct-the-minimum-bitwise-array-i | ✅ Easy Rust Solution | easy-rust-solution-by-erikrios-01p5 | \nimpl Solution {\n pub fn min_bitwise_array(nums: Vec<i32>) -> Vec<i32> {\n let n = nums.len();\n\n let mut results = Vec::with_capacity(n);\n | erikrios | NORMAL | 2024-11-10T02:30:57.296787+00:00 | 2024-11-10T02:30:57.296810+00:00 | 1 | false | ```\nimpl Solution {\n pub fn min_bitwise_array(nums: Vec<i32>) -> Vec<i32> {\n let n = nums.len();\n\n let mut results = Vec::with_capacity(n);\n\n \'outer: for num in nums {\n for i in 0..num {\n if i | (i + 1) == num {\n results.push(i);\n ... | 0 | 0 | ['Rust'] | 0 |
construct-the-minimum-bitwise-array-i | c++ 100% solution | c-100-solution-by-kartikbhutra02-ztt5 | 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 | kartikbhutra02 | NORMAL | 2024-11-09T12:39:16.032589+00:00 | 2024-11-09T12:39:16.032625+00:00 | 8 | 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 |
construct-the-minimum-bitwise-array-i | Java Straightforward Solution | java-straightforward-solution-by-curenos-39pa | Code\njava []\nclass Solution {\n public int getKthElement(int n) {\n int res = -1;\n for (int i = 0; i <= 1000; i++)\n if ((i | (i + 1)) == n)\n | curenosm | NORMAL | 2024-11-09T00:51:16.617062+00:00 | 2024-11-09T00:51:16.617092+00:00 | 5 | false | # Code\n```java []\nclass Solution {\n public int getKthElement(int n) {\n int res = -1;\n for (int i = 0; i <= 1000; i++)\n if ((i | (i + 1)) == n)\n return i;\n return res;\n }\n\n public int[] minBitwiseArray(List<Integer> nums) {\n return IntStream.range(0, nums.size())\n .map(it -> ... | 0 | 0 | ['Java'] | 0 |
construct-the-minimum-bitwise-array-i | Simple C++ Solution Beats 100% | simple-c-solution-beats-100-by-samarth_v-po5l | Code\ncpp []\nvector<int> minBitwiseArray(vector<int>& nums) {\n int n=nums.size();\n vector<int> ans(n);\n for(int i=0;i<n;++i){\n | samarth_verma_007 | NORMAL | 2024-11-04T18:09:15.823378+00:00 | 2024-11-04T18:09:15.823420+00:00 | 5 | false | # Code\n```cpp []\nvector<int> minBitwiseArray(vector<int>& nums) {\n int n=nums.size();\n vector<int> ans(n);\n for(int i=0;i<n;++i){\n if(nums[i]&1){\n int j=0;\n while(nums[i] & (1<<j)){\n ++j;\n }\n --j;\n... | 0 | 0 | ['C++'] | 0 |
construct-the-minimum-bitwise-array-i | Easy Way Solution in c++ | easy-way-solution-in-c-by-ni30_rjpt-mdpy | Initialization of temp: Moved the initialization of temp outside the inner loop and set it to -1 by default.\nReadability: Improved formatting and variable nami | ni30_rjpt | NORMAL | 2024-11-03T13:41:49.765101+00:00 | 2024-11-03T13:41:49.765129+00:00 | 1 | false | Initialization of temp: Moved the initialization of temp outside the inner loop and set it to -1 by default.\nReadability: Improved formatting and variable naming for clarity.\n# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the prob... | 0 | 0 | ['C++'] | 0 |
construct-the-minimum-bitwise-array-i | GO | Brute Force | go-brute-force-by-2107mohitverma-bjnv | 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 | 2107mohitverma | NORMAL | 2024-10-31T04:00:37.509522+00:00 | 2024-10-31T04:00:37.509558+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:\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 | ['Go'] | 0 |
construct-the-minimum-bitwise-array-i | Brute force | brute-force-by-kinnar-rbn1 | Intuition\n Describe your first thoughts on how to solve this problem. \nAs the constraints has limited small value used brute force\n# Approach\n Describe your | Kinnar | NORMAL | 2024-10-29T13:51:39.003464+00:00 | 2024-10-29T13:51:39.003496+00:00 | 0 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nAs the constraints has limited small value used brute force\n# Approach\n<!-- Describe your approach to solving the problem. -->\nBrute force\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n$$O(n)... | 0 | 0 | ['C++'] | 0 |
construct-the-minimum-bitwise-array-i | Python 94%, Easy to Understand. Optimize the brutal force method | python-94-easy-to-understand-optimize-th-69c2 | Approach\n Describe your approach to solving the problem. \nStart with brutal force. Iterate from 1 to nums[i] for each number to find if there is a number that | user8139UI | NORMAL | 2024-10-26T07:19:28.097451+00:00 | 2024-10-26T07:19:28.097477+00:00 | 3 | false | # Approach\n<!-- Describe your approach to solving the problem. -->\nStart with brutal force. Iterate from 1 to nums[i] for each number to find if there is a number that satisfy the requirement. \nThen, after some thinking, I optimize the starting point from 1 to n = 2**(cnt-1)-2. Where cnt is the index of the leading ... | 0 | 0 | ['Python'] | 0 |
construct-the-minimum-bitwise-array-i | C Solution | c-solution-by-nosetup-xum2 | Intuition\n Describe your first thoughts on how to solve this problem. \nNeed to clarify the question.\n\nThis problem is looking for a same size array with new | nosetup | NORMAL | 2024-10-25T20:17:18.112674+00:00 | 2024-10-25T20:17:18.112691+00:00 | 13 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nNeed to clarify the question.\n\nThis problem is looking for a same size array with new values that is\ngiven[i] = A, result[i] = B\nwhere,\nA = (B | B + 1)\nwe find individual \'B\' for each given.\nHere is a image showing A(orange) and ... | 0 | 0 | ['C'] | 0 |
construct-the-minimum-bitwise-array-i | Solution with explanation | solution-with-explanation-by-angielf-78g9 | Approach\nThe key insight here is that x | (x + 1) will always be equal to num if and only if the least significant bit of num is 1. This is because x | (x + 1) | angielf | NORMAL | 2024-10-25T08:54:55.061357+00:00 | 2024-10-25T08:54:55.061384+00:00 | 6 | false | # Approach\nThe key insight here is that x | (x + 1) will always be equal to num if and only if the least significant bit of num is 1. This is because x | (x + 1) will always set the least significant bit of num to 1.\n\nBy iterating over each num and finding the smallest x that satisfies the condition, we can construc... | 0 | 0 | ['Array', 'Bit Manipulation', 'PHP', 'Python3', 'JavaScript'] | 0 |
construct-the-minimum-bitwise-array-i | easy code | easy-code-by-npsy1811-aa5e | 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 | red_viper | NORMAL | 2024-10-25T07:07:39.521914+00:00 | 2024-10-25T07:07:39.521952+00:00 | 5 | 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 |
construct-the-minimum-bitwise-array-i | ✅ C# | readable solution 🚅 faster than 95% | c-readable-solution-faster-than-95-by-th-8zd1 | \n\nDon\'t hesitate to suggest or ask bellow about something that you don\'t understand\n\ncsharp []\npublic class Solution {\n public int[] MinBitwiseArray( | Thanat05 | NORMAL | 2024-10-23T19:56:36.771614+00:00 | 2024-10-23T19:57:08.375034+00:00 | 9 | false | \n\n**Don\'t hesitate to suggest or ask bellow about something that you don\'t understand**\n\n```csharp []\npublic class Solution {\n public int[] MinBitwiseArray(IList<int> nums) {\n List<int> l... | 0 | 0 | ['C#'] | 0 |
construct-the-minimum-bitwise-array-i | Runtime: 0ms Beats 100.00% || C++ || Java || Python3 | runtime-0ms-beats-10000-c-java-python3-b-eule | cpp []\nclass Solution {\npublic:\n vector<int> minBitwiseArray(vector<int>& nums) {\n vector<int> ans;\n\n for(int num : nums) {\n | Deviant25 | NORMAL | 2024-10-23T12:20:15.414232+00:00 | 2024-10-23T12:20:15.414256+00:00 | 17 | false | ```cpp []\nclass Solution {\npublic:\n vector<int> minBitwiseArray(vector<int>& nums) {\n vector<int> ans;\n\n for(int num : nums) {\n int ans_i = -1;\n\n for (int i = 0; i < num; ++i) {\n if ((i | (i + 1)) == num) {\n ans_i = i;\n ... | 0 | 0 | ['C++', 'Java', 'Python3'] | 0 |
construct-the-minimum-bitwise-array-i | Python3 | 4ms | Beats 99% | python3-4ms-beats-99-by-padth-u3hj | Code\npython3 []\nclass Solution:\n def minBitwiseArray(self, nums: List[int]) -> List[int]:\n result = []\n\n for n in nums:\n if n | padth | NORMAL | 2024-10-23T04:11:27.478762+00:00 | 2024-10-23T04:11:27.478797+00:00 | 4 | false | # Code\n```python3 []\nclass Solution:\n def minBitwiseArray(self, nums: List[int]) -> List[int]:\n result = []\n\n for n in nums:\n if n % 2 == 0:\n result.append(-1)\n continue\n\n i = 0\n while n & (1 << i) != 0:\n i += 1\... | 0 | 0 | ['Python3'] | 0 |
construct-the-minimum-bitwise-array-i | laziest brute force | laziest-brute-force-by-user5400vw-qv6h | 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 | user5400vw | NORMAL | 2024-10-23T04:08:54.305065+00:00 | 2024-10-23T04:08:54.305089+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 | ['Rust'] | 0 |
construct-the-minimum-bitwise-array-i | C Solution || Beats 99.12% | c-solution-beats-9912-by-heber_alturria-b3wq | c []\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* minBitwiseArray(int* nums, int numsSize, int* returnSize) {\n | Heber_Alturria | NORMAL | 2024-10-22T20:41:21.954307+00:00 | 2024-10-22T20:41:21.954333+00:00 | 5 | false | ```c []\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* minBitwiseArray(int* nums, int numsSize, int* returnSize) {\n int *result = calloc(numsSize, sizeof(int));\n *returnSize = numsSize;\n\n memset(result, -1, numsSize * sizeof(int));\n\n for (int i = 0; i < nums... | 0 | 0 | ['Array', 'Bit Manipulation', 'C'] | 0 |
construct-the-minimum-bitwise-array-i | 100% Python 1 line solution Bit manipulation | 100-python-1-line-solution-bit-manipulat-7gj6 | \n\n# Intuition\nPerforming a bitwise OR with n and n+1 will fill the leftmost 0 in n. Therefore to get the lowest value of n where n OR (n+1) == v, we can repl | El1247 | NORMAL | 2024-10-21T14:08:28.385991+00:00 | 2024-10-21T14:08:28.386025+00:00 | 2 | false | \n\n# Intuition\nPerforming a bitwise OR with `n` and `n+1` will fill the leftmost `0` in `n`. Therefore to get the lowest value of `n` where `n OR (n+1) == v`, we can replace the highest consecutive `1` in... | 0 | 0 | ['Bit Manipulation', 'Python3'] | 0 |
construct-the-minimum-bitwise-array-i | Simple Java Solution | simple-java-solution-by-prince_kumar1-htj7 | 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 | prince_kumar1 | NORMAL | 2024-10-20T10:27:47.680791+00:00 | 2024-10-20T10:27:47.680816+00:00 | 6 | 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 | ['Java'] | 0 |
construct-the-minimum-bitwise-array-i | Simple solution | simple-solution-by-liminghb123-ihbz | Intuition\n\n\n# Approach\n\n\n# Complexity\n- Time complexity:\nO(n*n)\n\n- Space complexity:\nO(n)\n\n# Code\ncpp []\nclass Solution {\npublic:\n vector<in | liminghb123 | NORMAL | 2024-10-20T02:32:03.143522+00:00 | 2024-10-20T02:32:03.143550+00:00 | 0 | false | # Intuition\n\n\n# Approach\n\n\n# Complexity\n- Time complexity:\nO(n*n)\n\n- Space complexity:\nO(n)\n\n# Code\n```cpp []\nclass Solution {\npublic:\n vector<int> minBitwiseArray(vector<int>& nums) {\n vector<int> ans;\n\n for (int j = 0; j < nums.size(); j++)\n {\n for (int i = 0; ... | 0 | 0 | ['C++'] | 0 |
construct-the-minimum-bitwise-array-i | Python, brute force | python-brute-force-by-blue_sky5-foc3 | \nclass Solution:\n def minBitwiseArray(self, nums: List[int]) -> List[int]:\n result = []\n for n in nums:\n for r in range(n):\n | blue_sky5 | NORMAL | 2024-10-19T17:52:03.644774+00:00 | 2024-10-19T17:52:03.644801+00:00 | 0 | false | ```\nclass Solution:\n def minBitwiseArray(self, nums: List[int]) -> List[int]:\n result = []\n for n in nums:\n for r in range(n):\n if r | (r + 1) == n:\n result.append(r)\n break\n else:\n result.append(-1)\n ... | 0 | 0 | [] | 0 |
construct-the-minimum-bitwise-array-i | Python Bruteforce | python-bruteforce-by-antarab-gq0l | \nclass Solution:\n def minBitwiseArray(self, nums: List[int]) -> List[int]:\n res=[]\n for x in nums:\n if x%2==0:\n | antarab | NORMAL | 2024-10-19T16:37:28.267897+00:00 | 2024-10-19T16:37:28.267929+00:00 | 3 | false | ```\nclass Solution:\n def minBitwiseArray(self, nums: List[int]) -> List[int]:\n res=[]\n for x in nums:\n if x%2==0:\n res.append(-1)\n else:\n for y in range(1,x):\n if y | (y+1) ==x:\n res.append(y)\n ... | 0 | 0 | ['Python3'] | 0 |
construct-the-minimum-bitwise-array-i | One line solution. Bit manipulation. O(n) | one-line-solution-bit-manipulation-on-by-c4yu | \nclass Solution:\n def minBitwiseArray(self, nums: List[int]) -> List[int]:\n return [(n&(n+1)) | ((~n&(n+1))//2-1) for n in nums]\n | xxxxkav | NORMAL | 2024-10-18T21:01:17.199300+00:00 | 2024-10-18T21:03:51.686299+00:00 | 7 | false | ```\nclass Solution:\n def minBitwiseArray(self, nums: List[int]) -> List[int]:\n return [(n&(n+1)) | ((~n&(n+1))//2-1) for n in nums]\n``` | 0 | 0 | ['Bit Manipulation', 'Python3'] | 0 |
construct-the-minimum-bitwise-array-i | TS Solution | ts-solution-by-ahmedhhamdy-x9ge | Create an array ans of the same length as nums, initialized with -1 (default value if no valid ans[i] is found).\n\nMain Loop:\n\nFor each element in nums, we t | ahmedhhamdy | NORMAL | 2024-10-18T14:10:40.710191+00:00 | 2024-10-18T14:10:40.710223+00:00 | 7 | false | Create an array ans of the same length as nums, initialized with -1 (default value if no valid ans[i] is found).\n\nMain Loop:\n\nFor each element in nums, we try to find the smallest x such that x | (x + 1) == nums[i].\nIf we find such a value, we update ans[i] and break out of the loop to move to the next index.\n\nT... | 0 | 0 | ['TypeScript'] | 0 |
construct-the-minimum-bitwise-array-i | Java, Easy And Optimized solution Using Bitwise Operator | java-easy-and-optimized-solution-using-b-cgog | 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 | vipin_121 | NORMAL | 2024-10-18T09:44:26.506267+00:00 | 2024-10-18T09:44:26.506297+00:00 | 4 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 0 | 0 | ['Java'] | 0 |
construct-the-minimum-bitwise-array-i | C++ Easy Solution :-> | c-easy-solution-by-atchayasmail-141y | Intuition\n Describe your first thoughts on how to solve this problem. \nGet the largest 2\'s power within nums[i]\n\n# Approach\n Describe your approach to sol | atchayasmail | NORMAL | 2024-10-18T04:29:18.714769+00:00 | 2024-10-18T04:29:18.714805+00:00 | 0 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nGet the largest 2\'s power within nums[i]\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nTake largest 2\'s power as k and keep incrementing it till the OR condition satisfies.\n\n# Complexity\n- Time complexity: O... | 0 | 0 | ['C++'] | 0 |
construct-the-minimum-bitwise-array-i | Solution | solution-by-hamzamks-qmc2 | \n\n# Code\njava []\nclass Solution {\n public int[] minBitwiseArray(List<Integer> nums) {\n int n = nums.size();\n int ans[] = new int[n];\n | hamzamks | NORMAL | 2024-10-17T11:51:55.121111+00:00 | 2024-10-17T11:51:55.121137+00:00 | 4 | false | \n\n# Code\n```java []\nclass Solution {\n public int[] minBitwiseArray(List<Integer> nums) {\n int n = nums.size();\n int ans[] = new int[n];\n // Initialize all elements to -1\n for (int i = 0; i < n; i++) {\n ans[i] = -1;\n }\n\n for (int i = 0; i < nums.size()... | 0 | 0 | ['Java'] | 0 |
construct-the-minimum-bitwise-array-i | [C] | c-by-zhang_jiabo-05pf | C []\nint * minBitwiseArray(\n\tconst int * const nums,\n\tconst int numsLen,\n\n\tint * const pRetsLen //out\n){\n\t*pRetsLen = numsLen;\n\tint * const rets = | zhang_jiabo | NORMAL | 2024-10-17T07:52:15.398970+00:00 | 2024-10-17T07:52:15.398994+00:00 | 2 | false | ```C []\nint * minBitwiseArray(\n\tconst int * const nums,\n\tconst int numsLen,\n\n\tint * const pRetsLen //out\n){\n\t*pRetsLen = numsLen;\n\tint * const rets = (int *)malloc(sizeof (int) * *pRetsLen);\n\n\tfor (int i = 0; i < numsLen; i += 1){\n\t\tif (nums[i] % 2 == 0){\n\t\t\trets[i] = -1;\n\t\t\tcontinue;\n\t\t}\... | 0 | 0 | ['C'] | 0 |
construct-the-minimum-bitwise-array-i | 💯💯 Simple solution using for loop (easy to understand) | simple-solution-using-for-loop-easy-to-u-be8b | 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 | CvQArRopoq | NORMAL | 2024-10-16T22:40:25.439298+00:00 | 2024-10-16T22:40:25.439338+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:\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 | ['Java'] | 0 |
construct-the-minimum-bitwise-array-i | Easy DP solution :) | easy-dp-solution-by-nomorenoove-e4i2 | \n\n# Code\ncpp []\nclass Solution {\n unordered_map<int, int> dp;\n\n int solve(int num){\n if(dp[num]) return dp[num];\n if(floor(log2(num | nomorenoove | NORMAL | 2024-10-16T21:10:31.595097+00:00 | 2024-10-16T21:10:31.595116+00:00 | 2 | false | \n\n# Code\n```cpp []\nclass Solution {\n unordered_map<int, int> dp;\n\n int solve(int num){\n if(dp[num]) return dp[num];\n if(floor(log2(num + 1)) == ceil(log2(num + 1))) return ((num + 1) / 2) - 1;\n\n int val = pow(2, (int)log2(num));\n\n return dp[num] = val + solve(num - val);\n... | 0 | 0 | ['C++'] | 0 |
construct-the-minimum-bitwise-array-i | Easy C++ Solution | easy-c-solution-by-mushahid3689-c09a | 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 | SyntaxTerror123 | NORMAL | 2024-10-16T07:55:41.164633+00:00 | 2024-10-16T07:55:41.164665+00:00 | 7 | 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 |
construct-the-minimum-bitwise-array-i | 47 ms Beats 97.69% | Easy Bitmask Solution | 47-ms-beats-9769-easy-bitmask-solution-b-rgcu | Complexity\n- Time complexity: O(10n)\n\n- Space complexity: O(n)\n\n# Code\npython3 []\nclass Solution:\n def __init__(self):\n # n <= 1000 < 1024 == | user1043p | NORMAL | 2024-10-16T07:06:58.746389+00:00 | 2024-10-16T07:06:58.746406+00:00 | 8 | false | # Complexity\n- Time complexity: $$O(10n)$$\n\n- Space complexity: $$O(n)$$\n\n# Code\n```python3 []\nclass Solution:\n def __init__(self):\n # n <= 1000 < 1024 == 2 ** 10\n self.masks = [0x0, 0x1, 0x3, 0x7, 0xf, 0x1f, 0x3f, 0x7f, 0xff, 0x1ff, 0x3ff]\n\n def minBitwiseArray(self, nums: List[int]) ->... | 0 | 0 | ['Python3'] | 0 |
construct-the-minimum-bitwise-array-i | Java Easy Solution | java-easy-solution-by-iamsd-q98y | Code\njava []\nclass Solution {\n public int[] minBitwiseArray(List<Integer> nums) {\n int len = nums.size();\n int[] ans = new int[len];\n | iamsd_ | NORMAL | 2024-10-15T06:16:08.818426+00:00 | 2024-10-15T06:16:08.818460+00:00 | 1 | false | # Code\n```java []\nclass Solution {\n public int[] minBitwiseArray(List<Integer> nums) {\n int len = nums.size();\n int[] ans = new int[len];\n\n for (int i = 0; i < len; i++) {\n boolean flag = true;\n for (int j = 1; j < nums.get(i); j++) {\n if ((j | ... | 0 | 0 | ['Java'] | 0 |
construct-the-minimum-bitwise-array-i | [Python] brutal force solution that beat 90% | python-brutal-force-solution-that-beat-9-ycp3 | \nclass Solution:\n def minBitwiseArray(self, nums: List[int]) -> List[int]:\n # build a map from value to index to easy access answer list\n n | wangw1025 | NORMAL | 2024-10-15T04:21:14.972141+00:00 | 2024-10-15T04:21:14.972175+00:00 | 5 | false | ```\nclass Solution:\n def minBitwiseArray(self, nums: List[int]) -> List[int]:\n # build a map from value to index to easy access answer list\n num_map = collections.defaultdict(list)\n for idx, n in enumerate(nums):\n num_map[n].append(idx)\n \n ans = [-1] * len(nums)\... | 0 | 0 | ['Python3'] | 0 |
construct-the-minimum-bitwise-array-i | Java | java-by-sumeetrayat-snm9 | \n\n# Code\njava []\nclass Solution {\n public int[] minBitwiseArray(List<Integer> nums) {\n\n\t\t\n\t\tint count=0;\n\t\tint ans[]= new int[nums.size()];\n\ | sumeetrayat | NORMAL | 2024-10-15T03:05:31.640444+00:00 | 2024-10-15T03:05:31.640469+00:00 | 4 | false | \n\n# Code\n```java []\nclass Solution {\n public int[] minBitwiseArray(List<Integer> nums) {\n\n\t\t\n\t\tint count=0;\n\t\tint ans[]= new int[nums.size()];\n\t\tfor (int i = 0; i<=nums.size()-1; i++) {\n\t\t\t\n\t\t\tfor (int j = 0; j<=nums.get(i); j++) {\n\t\t\t\t\n\t\t\t\tif((j | (j + 1)) == nums.get(i))\n\t\t\t... | 0 | 0 | ['Java'] | 0 |
construct-the-minimum-bitwise-array-i | Ruby one-liner, beats 100%/100% | ruby-one-liner-beats-100100-by-dnnx-wd9n | ruby []\n# @param {Integer[]} nums\n# @return {Integer[]}\ndef min_bitwise_array(nums)\n nums.map { |n| n == 2 ? -1 : n - (((n ^ (n + 1)) + 1) / 4) } \nend\n | dnnx | NORMAL | 2024-10-14T16:23:21.077297+00:00 | 2024-10-14T16:23:21.077328+00:00 | 4 | false | ```ruby []\n# @param {Integer[]} nums\n# @return {Integer[]}\ndef min_bitwise_array(nums)\n nums.map { |n| n == 2 ? -1 : n - (((n ^ (n + 1)) + 1) / 4) } \nend\n``` | 0 | 0 | ['Ruby'] | 0 |
construct-the-minimum-bitwise-array-i | [Python] Brute force | python-brute-force-by-pbelskiy-o0up | \nclass Solution:\n def minBitwiseArray(self, nums: List[int]) -> List[int]:\n ans = []\n\n for n in nums:\n for x in range(n):\n | pbelskiy | NORMAL | 2024-10-14T12:58:00.631835+00:00 | 2024-10-14T12:58:00.631865+00:00 | 1 | false | ```\nclass Solution:\n def minBitwiseArray(self, nums: List[int]) -> List[int]:\n ans = []\n\n for n in nums:\n for x in range(n):\n if x | (x + 1) == n:\n ans.append(x)\n break\n else:\n ans.append(-1)\n\n ... | 0 | 0 | ['Python'] | 0 |
construct-the-minimum-bitwise-array-i | Beats 100.00% | 1-liner | beats-10000-1-liner-by-nicholasgreenwood-ajki | \n\n\n\ntypescript []\nfunction minBitwiseArray(nums: number[]): number[] {\n return nums.map((num) => (num === 2 ? -1 : (((-num - 2) ^ num) >> 2) + num))\n}\n | NicholasGreenwood | NORMAL | 2024-10-14T11:15:52.143063+00:00 | 2024-10-18T14:08:44.343571+00:00 | 32 | false | \n\n\n\n```typescript []\nfunction minBitwiseArray(nums: number[]): number[] {\n return num... | 0 | 0 | ['TypeScript', 'JavaScript'] | 0 |
construct-the-minimum-bitwise-array-i | Easy | easy-by-shanku1999-1jz8 | 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 | shanku1999 | NORMAL | 2024-10-14T11:12:36.234485+00:00 | 2024-10-14T11:12:36.234513+00:00 | 8 | 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 | ['Python3'] | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.