Minimize the Sum with Ceiling Halves
Updated
Problem statement
Perform exactly operations changes to the nonnegative integer array values. In one change, choose any element x and replace it with ceil(x / 2).
Return the smallest possible sum after all changes, as a signed 64-bit integer. The same position may be chosen more than once.
For this exercise, assume zero is allowed. Replacing 0 or 1 leaves it unchanged, so any remaining changes may be spent on those values without changing the result.
Function
minimumHalvedSum(values: int[], operations: int) → longExamples
Example 1
values = [5,3]operations = 1return = 6Replace 5 with 3. The array becomes [3,3], whose sum is 6.
Example 2
values = [5]operations = 2return = 2The only value changes from 5 to 3, then to 2.
Example 3
values = [0,1]operations = 4return = 1Both values are fixed points under ceiling halves. All four changes leave the sum at 1.
Constraints
1 <= values.length <= 5000.0 <= values[i] <= 1000000000.0 <= operations <= 100000.
More Squarepoint Capital interview questions
- Evaluating Circuit ExpressionsOA · Seen Jul 2026
- Match an XOR-Adjusted SumOA · Seen Oct 2025
- Maximize Palindromic WordsOA · Seen Oct 2025
- Longest Increasing Subsequence from Two ArraysOA · Seen Oct 2025
- Resolve Overlapping Price RangesOA · Seen Dec 2024
- Empty ShelfOA · Seen Sep 2024
- Suggested ProductsOA · Seen Sep 2024
- Newton Square Root to a Guaranteed TolerancePHONE SCREEN · Seen Nov 2026
- Probability of Consecutive HeadsPHONE SCREEN · Seen Nov 2026
- Three Points in a Semicircle: Monte Carlo EstimatePHONE SCREEN · Seen Nov 2026
Similar questions at other companies
- Maximum ScoreNVIDIA · OANVIDIA interview questions
- Maximize Revenue from Decreasing InventoryChubb · OAChubb interview questions
- Rearrange Songs by AuthorZomato / Eternal · OAZomato / Eternal interview questions
- Effective ManagerGoldman Sachs · OAGoldman Sachs interview questions
- Tennis Court SchedulingAtlassian · PHONE SCREEN · ONSITE INTERVIEWAtlassian interview questions
- Maximum Number of Events That Can Be AttendedByteDance · PHONE SCREENByteDance interview questions
- Minimize Total Weight After HalvingAmazon · ONSITE INTERVIEW
- 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