Talentd
FleetCode

3688. Bitwise OR of Even Numbers in an Array

Easy84.9% acceptance2 companies

You are given an integer array nums.

Return the bitwise OR of all even numbers in the array.

If there are no even numbers in nums, return 0.

Example 1:

Input: nums = [1,2,3,4,5,6]

Output: 6

Explanation:

The even numbers are 2, 4, and 6. Their bitwise OR equals 6.

Example 2:

Input: nums = [7,9,11]

Output: 0

Explanation:

There are no even numbers, so the result is 0.

Example 3:

Input: nums = [1,8,16]

Output: 24

Explanation:

The even numbers are 8 and 16. Their bitwise OR equals 24.

Constraints:

  • 1 <= nums.length <= 100
  • 1 <= nums[i] <= 100

Asked at 2 companies

Hints open one at a time

Hint 1
Simulate as described
3:58
Still stuck?Read the written solution, or watch a walkthrough.
Open solution
Loading editor…
1class Solution:
2 def evenNumberBitwiseORs(self, nums: List[int]) -> int:
3
Starter codePython 3Spaces: 4
Examples
Input
[1,2,3,4,5,6]
Input
[7,9,11]
Input
[1,8,16]
Your code is saved on this device.Solution