Salesforce is running an advanced optimization task to compress datasets stored in an array named data, where each element represents the size of a data chunk. The task is to minimize the largest data chunk size in the array by repeatedly applying the operation below any number of times:
The goal is to output the smallest possible maximum element of data[] after the operation sequence is carried out optimally. Because the '&' operation doesn't change when repeated and always moves in one direction, the basic method of comparing pairs is too slow under the new rules—you need to find a faster solution that works in O(n) time.
Example n = 2 data[] = [1, 2] Choose range [0, 1]. First with i = 0, set data[0] = 1 & 2 = 0. Then with i = 1, set data[1] = 2 & 0 = 0. The array is now [0, 0], and the maximal chunk size is 0.
Function Description Complete the function getOptimizedData in the editor below. The function must return the minimized maximum value achievable.
getOptimizedData has the following parameter:
Returns
Constraints
Nvidia • Pending