Practice Find a Value of a Mysterious Function Closest to Target
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Find a Value of a Mysterious Function Closest to Target
Problem Statement
For valid indices l and r, func(arr, l, r) is the bitwise AND of every entry from arr[l] through arr[r] when l <= r. If r < l, the supplied function returns -1,000,000,000. Given arr and target, return the smallest absolute difference |func(arr, l, r) - target| over choices with 0 <= l, r < arr.length.
Source: Find a Value of a Mysterious Function Closest to Target on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
arr = [9,12,3,7,15], target = 5
2
# Example 2
arr = [1000000,1000000,1000000], target = 1
999999
# Example 3
arr = [1,2,4,8,16], target = 0
0
Constraints
Related LeetCode Problems
Practice more problems similar to Find a Value of a Mysterious Function Closest to Target.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.