FastPrepMinimum Operations to Halve an Array Sum
Problems/Minimum Operations to Halve an Array Sum

Minimum Operations to Halve an Array Sum

Grab logoGrab● MediumNEW GRADPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report gives the goal of halving and one example. It does not give input limits or say what happens when the same index is used again. Our version is about 96% the same as the reported question.

Given a nonempty array of positive integers values, one operation chooses one position and replaces its current value x with floor(x / 2).

Let originalSum be the sum before any operations and currentSum the sum afterward. Return the minimum number of operations needed until 2 * currentSum <= originalSum. The same position may be chosen more than once.

Function

minimumHalvingOperations(values: int[]) → int

Examples

Example 1

values = [7,4,8,1]return = 3

The original sum is 20. Halving 8, then 7, then a current 4 reaches sum 10 in three operations.

Example 2

values = [10]return = 1

Replacing 10 by 5 reaches exactly half the original sum.

Constraints

  • 1 <= values.length <= 100000.
  • 1 <= values[i] <= 1000000000.

More Grab Phone Screen questions

  • Movie LRU CachePHONE SCREEN · Seen Jan 2026
  • Smallest Point with Maximum Inclusive Interval OverlapPHONE SCREEN · Seen Nov 2021

Similar questions at other companies

  • Tennis Court SchedulingAtlassian · PHONE SCREEN · ONSITE INTERVIEWAtlassian interview questions
  • Maximum Number of Events That Can Be AttendedByteDance · PHONE SCREENByteDance interview questions
  • Defer Expenses to Preserve BalanceDRW · PHONE SCREENDRW interview questions
  • Minimize Array Sum After K Halving OperationsDocuSign · PHONE SCREENDocuSign interview questions
  • Maximum Number of Events That Can Be AttendedSnowflake · PHONE SCREENSnowflake interview questions
  • Automation Pipeline, Part 3: Stage DurationPlaid · PHONE SCREENPlaid interview questions
  • Minimum Sum After K Ceiling HalvingsAdobe · PHONE SCREENAdobe interview questions
  • Furthest Building with Bricks and LaddersAmazon · PHONE SCREEN
  • Schedule Unit-Time Jobs for the Most ProfitScale AI · PHONE SCREENScale AI interview questions
  • Minimum Meeting RoomsSentry · PHONE SCREENSentry interview questions
All Grab interview questionsSee Grab hiring insights
Saved
class Solution {
    public int minimumHalvingOperations(int[] values) {
        // Write your code here.
    }
}
Checking account…