Amazon OA | Subarray with Maximum Bitwise AND

amazon logo
amazon
Ongoing
September 1, 202544 reads

Summary

I completed an Amazon Online Assessment which featured a problem focused on finding the maximum bitwise AND of a subarray, with the allowance to increment array elements a limited number of times.

Full Experience

I recently took an Online Assessment for Amazon. The assessment featured a particularly interesting problem where I needed to find the maximum bitwise-AND of a subarray of a given size m, with the constraint of being able to increment any number in the array at most k times. I found the problem to be quite a brain-teaser, especially optimizing for the bitwise AND property across different subarrays.

Interview Questions (1)

Q1
Maximize Subarray Bitwise AND with K Increments
Data Structures & AlgorithmsHard

Given n sized array of integers,

find the maximum bitwise-AND of a subarray of size m

You can add 1 (increment) to any number in the array, atmost k times.

Example 1 :

n = 4
arr : [1,4,10,2]
k = 8
m = 2

Ans : 10

Increment the last element 2 -> 10 Hence the maximum subarray bitwise would be 10

Example 2 :

n = 3
arr = [1,1,1]
k = 3
m = 3

Ans : 2 Add 1 to each element of the array -> [2,2,2] Hence the maximum subarray bitwise would be 2

Discussion (0)

Share your thoughts and ask questions

Join the Discussion

Sign in with Google to share your thoughts and ask questions

No comments yet

Be the first to share your thoughts and start the discussion!