Check if Bitwise OR Has Trailing Zeros - Problem

You are given an array of positive integers nums. You have to check if it is possible to select two or more elements in the array such that the bitwise OR of the selected elements has at least one trailing zero in its binary representation.

For example, the binary representation of 5, which is "101", does not have any trailing zeros, whereas the binary representation of 4, which is "100", has two trailing zeros.

Return true if it is possible to select two or more elements whose bitwise OR has trailing zeros, return false otherwise.

Input & Output

Example 1 — Basic Case
$ Input: nums = [2,1,4]
Output: true
💡 Note: We can select 2 and 4. Their OR is 2|4 = 6, which is 110 in binary (has one trailing zero).
Example 2 — All Odd Numbers
$ Input: nums = [1,3,5]
Output: false
💡 Note: All numbers are odd. Any OR combination will be odd (no trailing zeros). 1|3=3, 1|5=5, 3|5=7, 1|3|5=7.
Example 3 — Multiple Even Numbers
$ Input: nums = [2,4,6,8]
Output: true
💡 Note: Multiple even numbers exist. For example, 2|4 = 6 (binary: 110) has trailing zero.

Constraints

  • 2 ≤ nums.length ≤ 100
  • 1 ≤ nums[i] ≤ 100

Visualization

Tap to expand
Check if Bitwise OR Has Trailing ZerosInput: [2,1,4]214010 (even)001 (odd)100 (even)Check Combinations:2 | 4 = 6 (binary: 110)Has trailing zero! ✓Output: true
Understanding the Visualization
1
Input
Array of positive integers
2
Process
Find if any combination's OR is even
3
Output
Boolean result
Key Takeaway
🎯 Key Insight: A number has trailing zeros iff it's even - just count even numbers!
Asked in
Google 15 Microsoft 12 Amazon 8
8.5K Views
Medium Frequency
~8 min Avg. Time
245 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen