This is a verified interview question from Salesforce. Candidates reporting seeing this problem in recent Online Assessments (OAs) and onsite rounds. Mastering "Salesforce Data Compression - Salesforce Online Assessment" covers key patterns like Arrays.
"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: 1. Select a range [l, r], where 0 <= l < r < size of data[]. 2. Select an index i in the range [0, r - l]. 3. Update data[l + i] = data[l + i] & data[r - i]. 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: * data[data[0], ... data[n-1]]: an array of integers. Returns * int: the minimized maximum chunk size. Constraints * 1 <= n <= 10^6 * 1 <= data[i] < 2^31 * Time limit guarantees only solutions with overall complexity O(n) (or faster) will pass."
Join thousands of developers practicing for Salesforce.