Title: #2680 - Maximum OR - LeetCode JavaScript Solutions
Open Graph Title: #2680 - Maximum OR - LeetCode JavaScript Solutions
X Title: #2680 - Maximum OR - LeetCode JavaScript Solutions
Description: You are given a 0-indexed integer array nums of length n and an integer k. In an operation, you can choose an element and multiply it by 2. ...
Open Graph Description: You are given a 0-indexed integer array nums of length n and an integer k. In an operation, you can choose an element and multiply it by 2. ...
X Description: You are given a 0-indexed integer array nums of length n and an integer k. In an operation, you can choose an element and multiply it by 2. ...
Keywords:
Opengraph URL: https://leetcodejavascript.com/solutions/maximum-or
Domain: leetcodejavascript.com
{"@context":"https://schema.org","@type":"Code","url":"https://leetcodejavascript.com/solutions/maximum-or","name":"#2680 - Maximum OR - LeetCode JavaScript Solutions","description":"You are given a 0-indexed integer array nums of length n and an integer k. In an operation, you can choose an element and multiply it by 2. ...","programmingLanguage":"JavaScript","codeRepository":"https://github.com/JoshCrozier/leetcode-javascript","codeSampleType":"JavaScript","text":"/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number}\n */\nvar maximumOr = function(nums, k) {\n const n = nums.length;\n const prefixOr = new Array(n + 1).fill(0n);\n const suffixOr = new Array(n + 1).fill(0n);\n\n for (let i = 0; i < n; i++) {\n prefixOr[i + 1] = prefixOr[i] | BigInt(nums[i]);\n }\n\n for (let i = n - 1; i >= 0; i--) {\n suffixOr[i] = suffixOr[i + 1] | BigInt(nums[i]);\n }\n\n let maxOr = 0n;\n for (let i = 0; i < n; i++) {\n maxOr = maxOr > (prefixOr[i] | (BigInt(nums[i]) << BigInt(k)) | suffixOr[i + 1])\n ? maxOr\n : (prefixOr[i] | (BigInt(nums[i]) << BigInt(k)) | suffixOr[i + 1]);\n }\n\n return Number(maxOr);\n};","keywords":"LeetCode 2680, #2680 - Maximum OR, Medium, JavaScript solution","learningResourceType":"Code","isAccessibleForFree":true,"educationalLevel":"intermediate","interactivityType":"mixed"}
| author | LeetCodeJavascript.com |
| og:type | article |
| og:image | https://leetcodejavascript.com/og-image.jpg |
| og:site_name | LeetCode JavaScript Solutions |
| twitter:card | summary_large_image |
| twitter:url | https://leetcodejavascript.com/solutions/maximum-or |
| twitter:image | https://leetcodejavascript.com/og-image.jpg |
| twitter:creator | @joshcrozier |
| theme-color | #1f2937 |
Links:
| LeetCodeJavascript.com | https://leetcodejavascript.com/ |
| Star on GitHub | https://github.com/JoshCrozier/leetcode-javascript |
| Back to all solutions | https://leetcodejavascript.com |
| View on LeetCode | https://leetcode.com/problems/maximum-or/ |
| View on GitHub | https://github.com/JoshCrozier/leetcode-javascript/blob/master/solutions/2680-maximum-or.js |
| Array | https://leetcodejavascript.com/tags/array |
| Greedy | https://leetcodejavascript.com/tags/greedy |
| Bit Manipulation | https://leetcodejavascript.com/tags/bit-manipulation |
| Prefix Sum | https://leetcodejavascript.com/tags/prefix-sum |
| Josh Crozier | https://joshcrozier.com |
Viewport: width=device-width, initial-scale=1.0
Robots: index, follow