Array Operations
Updated
Problem statement
You are given an array of n elements and two variables, x and y.
In each operation, you can:
- Subtract
xfrom one element of the array. - Subtract
yfrom the remaining elements.
Your task is to find the minimum number of operations required to make every element of the array ≤ 0.
Input Format:
- The first line contains an integer
n, the number of elements in the array. - The second line contains
nspace-separated integers representing the array. - The third line contains two integers,
xandy, wherex > y.
Output:
Print the minimum number of operations to make each element ≤ 0.
Function
minOperations(arr: int[], x: int, y: int) → intExamples
Example 1
arr = [10, 20, 30, 40, 50]x = 5y = 2return = 14With 13 operations, the elements 30, 40, and 50 would require at least 2 + 5 + 8 = 15 selections in total, so 13 operations are impossible. With 14 operations, the shared subtraction is 28 and only 1 + 4 + 8 = 13 selections are required, so the minimum is 14.
Constraints
🍊🍊
More GreyOrange interview questions
Similar questions at other companies
- Server Upgrade PlanningWells Fargo · OAWells Fargo interview questions
- Find Minimum TimeAlphaSense · OA
- Find Minimum TimeBlackRock · OABlackRock interview questions
- Maximize Pipeline Throughput Under a Scaling BudgetMicrosoft · OAMicrosoft interview questions
- Rock JumpingIMC Trading · OAIMC Trading interview questions
- Minimum Robot and Human Fulfillment TimeAmazon · OA
- Minimize Maximum Group DifferenceDRW · OADRW interview questions
- Array NullificationQRT · OA
- Minimum HeightSnowflake · OASnowflake interview questions
- Pipeline Throughput Maximization Under BudgetUber · OAUber interview questions