You're a Salesforce admin getting ready to spin up several scratch orgs for a big demo. Each scratch org needs to ship with exactly the same seed data — the same number of records in every custom field — so your demo looks flawless across environments.
The counts you already have live in the array recordCounts, where recordCounts[i] is the number of seed records you've pre-loaded for the i-th custom field. To build the orgs, the record count in every field must be perfectly divisible by the number of orgs you create (k, where k >= 2).
You can insert new seed records or delete extras; each insert or delete is one modification. Your goal is to find the fewest total modifications required to spin up at least 2 identical scratch orgs.
Example n = 5 recordCounts = [4, 7, 5, 11, 15] For 2 orgs the per-field changes are [0, 1, 1, 1, 1] -> total 4. For 3 orgs they are [1, 1, 1, 1, 0] -> total 4. Any org count k >= 2 is allowed, but the minimum achievable number of modifications is 4.
Function Description Complete the function getMinimumRecords in the editor below.
getMinimumRecords has the following parameter:
Returns
Constraints
Sample Case 0
Sample Input 5 3 8 7 6 4
Sample Output 2
Explanation With 2 orgs the adjustments are [+1, 0, -1, 0, 0] -> 2 total modifications, which is optimal.
Nvidia • Pending