3171. Find Subarray With Bitwise AND Closest to K
You are given an array
nums
and an integerk
. You need to find a subarray ofnums
such that the absolute difference betweenk
and the bitwiseAND
of the subarray elements is as small as possible. In other words, select a subarraynums[l..r]
such that|k - (nums[l] AND nums[l + 1] ... AND nums[r])|
is minimum.Return the minimum possible value of the absolute difference.
A subarray is a contiguous non-empty sequence of elements within an array.
c++
1 | class Solution { |
c++
1 |
|