This is a verified interview question from Salesforce. Candidates reporting seeing this problem in recent Online Assessments (OAs) and onsite rounds. Mastering "Resource Distribution" covers key patterns like DP.
"A Salesforce administrator is managing resource allocation across n regions for a marketing campaign. These regions are represented by an array arr of length n, where initially, each element of the array is set to 0. The administrator needs to perform q updates on the array arr, following these rules: 1. An update is specified as (i, x), where: * i is the index of the primary region to which x units of resources are allocated. * Neighboring regions also receive a portion of the resources, with the allocated units decreasing as the distance from i increases. 2. Specifically, for each region j, the resources are updated as: arr[j] = arr[j] + x - |j - i| This applies to all regions j such that: 0 <= j < n. After all q updates are applied, output the final resource allocation across all regions. For example, n = 5, q = 3, query = [[2, 2], [1, 3], [4, 1]]. Initially, arr = [0, 0, 0, 0, 0] * qry0 = [2, 2] - Add 2 to index 2, add 1 to indices 1 and 3. arr = [0, 1, 2, 1, 0] * qry1 = [1, 3] - Add 3 to index 1, add 2 to index 0, add 2 to index 2, add 1 to index 3. arr = [2, 4, 4, 2, 0] * qry2 = [4, 1] - Add 1 to index 4. arr = [2, 4, 4, 2, 1] Finally, arr = [2, 4, 4, 2, 1] after all the updates are applied. Hence we return [2, 4, 4, 2, 1]."
Join thousands of developers practicing for Salesforce.