#2980
Easy Algorithms Check if bitwise or has trailing zeros
Array Bit Manipulation
71.1% acceptance
Feb 25, 2026
139
11
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, or false otherwise.
Solution
Rust
Time O(n)
Space O(1)
impl Solution {
pub fn has_trailing_zeros(nums: Vec<i32>) -> bool {
// OR has trailing zeros iff all selected elements are even
// We need at least 2 even numbers
nums.iter().filter(|&&x| x % 2 == 0).count() >= 2
}
}