Search
⌘K

Leetcode 3171. Find Subarray With Bitwise OR Closest to K

Find a contiguous subarray whose bitwise OR is as close as possible to k (minimize |k - OR(nums[l..r])|). The challenge is to exploit that OR accumulates bits (so extending a segment yields only O(bit-length) distinct OR values) to avoid quadratic enumeration and solve in near-linear time for n up to 1e5.


Question Timeline

See when this question was last asked and where, including any notes left by other candidates.

Comments

Your account is free and you can post anonymously if you choose.