Redistribute Megaseeds
Updated
Problem statement
You are given num crates in a line, where seeds[i] is the number of seeds in crate i. At least one crate is non-empty.
In one operation, move one seed from a crate to its immediately adjacent crate on the left or right.
Choose any integer div > 1 and redistribute the seeds so that every crate contains a multiple of div. Seeds cannot be created or removed.
Return the minimum number of operations over all valid choices of div. If no such divisor exists, return -1.
Function
redistributeMegaseeds(num: int, seeds: int[]) → longExamples
Example 1
num = 4seeds = [0, 1, 0, 1]return = 2Choose div = 2 and move the seed from crate 3 left twice. The final counts can be [0, 2, 0, 0].
Example 2
num = 3seeds = [1, 2, 3]return = 1Choose div = 3 and move one seed from crate 0 to crate 1, producing [0, 3, 3].
Constraints
- The number of crates,
1 <= num <= 10^6. - The initial number of seeds in each crate,
0 <= seeds[i] <= 10^6. - Out of
seeds[0],seeds[1],seeds[2], ...,seeds[num-1], at least one is assured to be greater than0.
More Rubrik interview questions
- Colored Rooted TreeONSITE INTERVIEW · Seen Nov 2026
- Delete and Freeze GameOA · Seen Nov 2026
- Delete K Subsets for Maximum ScoreOA · Seen Nov 2026
- Distribute Elements Into Two Arrays IIOA · Seen Nov 2026
- Minimum Replacements to Sort the ArrayOA · Seen Nov 2026
- All Balanced Strings from Minimum Parenthesis InsertionsONSITE INTERVIEW · Seen Nov 2026
- Insert into a Left-Complete Binary TreeONSITE INTERVIEW · Seen Oct 2026
- Thread-Safe Request Counts by AttributeONSITE INTERVIEW · Seen Oct 2026
- Minimum Swaps To Binary PalindromeOA · Seen Apr 2026
- Get Minimum OperationsOA · Seen Nov 2024
Similar questions at other companies
- Minimum Cost K-Capable ModelsMicrosoft · OAMicrosoft interview questions
- Optimal TransferSnowflake · OASnowflake interview questions
- Minimum Redistribution CostAmazon · OA
- Gas Station Loop StartNutanix · OANutanix interview questions
- Maximum Distinct Items Within a BudgetAdobe · OAAdobe interview questions
- Minimum AmountBelvedere Trading · OA
- Focus on Efficiency (2024 NG)Google · OAGoogle interview questions
- Running Through Walls with Limited EnergyScale AI · OAScale AI interview questions
- Make the Array PositiveAtlassian · OAAtlassian interview questions
- Maximize Compatible Car RidersUber Freight · PHONE SCREEN · ONSITE INTERVIEWUber Freight interview questions