Talentd
FleetCode

3173. Bitwise OR of Adjacent Elements

Easy94.8% acceptance1 companyPremium elsewhere, free here

Given an array nums of length n, return an array answer of length n - 1 such that answer[i] = nums[i] | nums[i + 1] where | is the bitwise OR operation.

Example 1:

Input: nums = [1,3,7,15]

Output: [3,7,15]

Example 2:

Input: nums = [8,4,2]

Output: [12,6]

Example 3:

Input: nums = [5,4,9,11]

Output: [5,13,11]

Constraints:

  • 2 <= nums.length <= 100
  • 0 <= nums[i] <= 100

Asked at 1 company

Hints open one at a time

Hint 1
Iterate over array and calculate each element of the resulting array using | operation.
1:12
Still stuck?Read the written solution, or watch a walkthrough.
Open solution
Loading editor…
1class Solution:
2 def solve(self):
3 pass
4
Starter codePython 3Spaces: 4
Examples
Input
[1,3,7,15]
Input
[8,4,2]
Input
[5,4,9,11]
Your code is saved on this device.Solution