FastPrepArray Operations
Problems/Array Operations

Array Operations

GreyOrange logoGreyOrange● MediumOA

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem statement

You are given an array of n elements and two variables, x and y.

In each operation, you can:

  • Subtract x from one element of the array.
  • Subtract y from 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 n space-separated integers representing the array.
  • The third line contains two integers, x and y, where x > y.

Output:

Print the minimum number of operations to make each element ≤ 0.

Function

minOperations(arr: int[], x: int, y: int) → int

Examples

Example 1

arr = [10, 20, 30, 40, 50]x = 5y = 2return = 14

With 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

  • Roman Numerals in StringsOA · Seen Oct 2024
  • Triangle and PointsOA · Seen Oct 2024

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
See GreyOrange hiring insights
Saved
class Solution {
    public int minOperations(int[] arr, int x, int y) {
      // write your code here
    }

}
Checking account…