Skip to main content
Back to problems
#3173
Easy Algorithms

Bitwise or of adjacent elements

Array Bit Manipulation
94.8% acceptance
Mar 31, 2026
24
2
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.

Solution

Rust
Time O(n)
Space O(1)
LeetCode
solution.rs
impl Solution {
  pub fn or_array(nums: Vec<i32>) -> Vec<i32> {
    (0..nums.len() - 1).map(|i| nums[i] | nums[i + 1]).collect()
  }
}