FastPrepHalve Values Until All Are at Most k
Problems/Halve Values Until All Are at Most k

Halve Values Until All Are at Most k

Adobe logoAdobe● EasyFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: This problem counts the fewest halvings that bring every value of a list down to k or below. The source is a post from June 2022 (seven months of experience, off-campus MTS opening). This was the first question of the earliest live interview (5 May 2022, about 50 minutes), ahead of a BST check. The report leaves open the limits, the examples and what happens with zeros. It allows the same value to be picked more than once, and its values may be decimals.

Our choices: halving is exact with no rounding. Values are from 0 to 10^9 with up to 6 decimal places. k is from 0.001 to 10^9 with up to 3 decimal places. There are up to 2000 values. The examples are new.

Our version is about 90% the same as the reported question.

You are given an array nums of non-negative numbers, which may have fractional parts, and a positive number k. In one operation you pick any element of nums and replace it with half of its value, with no rounding (for example, 5 becomes 2.5). The same element may be picked again later.

Return the smallest number of operations after which every element of nums is at most k.

Function

minHalvings(nums: double[], k: double) → int

Examples

Example 1

nums = [10.0,3.0,4.5]k = 2.5return = 4

10 needs two halvings (10, 5, 2.5) and 3 needs one (3, 1.5). 4.5 needs one (2.25). The total is 2 + 1 + 1 = 4.

Example 2

nums = [0.5,1.25,2.0]k = 2.0return = 0

Every number is already at most 2 (2 equals k, which is allowed), so no halving is needed and the answer is 0.

Example 3

nums = [100.0]k = 0.75return = 8

100 becomes 50, 25, 12.5, 6.25, 3.125, 1.5625 and then 0.78125, which is still above 0.75, so one more halving gives 0.390625. That is 8 halvings.

Constraints

  • 1 <= nums.length <= 2000
  • 0 <= nums[i] <= 10^9, with at most 6 digits after the decimal point
  • 0.001 <= k <= 10^9, with at most 3 digits after the decimal point

More Adobe Phone Screen questions

  • Evaluate a Parenthesized Integer ExpressionPHONE SCREEN · Seen Oct 2026
  • All Elements of Two BSTs in OrderPHONE SCREEN · Seen Aug 2026
  • Rotate an Array In PlaceOA · PHONE SCREEN · Seen Aug 2026
  • Binary Tree Level-Order Traversal by LevelsPHONE SCREEN · ONSITE INTERVIEW · Seen Aug 2026
  • Count Occurrences in a Sorted ArrayPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
  • Count Pairs with Absolute Difference KPHONE SCREEN · Seen Jul 2026
  • Count Subsets with Sum KPHONE SCREEN · Seen Jul 2026
  • Numbers with Exactly Three DivisorsPHONE SCREEN · Seen Jul 2026
  • Sum of Even Nodes on a Path in a Numbered Binary TreePHONE SCREEN · Seen Jul 2026
  • Largest Value in Every Sliding WindowPHONE SCREEN · Seen Jul 2026

Similar questions at other companies

  • Maximize Revenue from Decreasing InventoryChubb · OAChubb interview questions
  • Tennis Court SchedulingAtlassian · PHONE SCREEN · ONSITE INTERVIEWAtlassian interview questions
  • Maximum Number of Events That Can Be AttendedByteDance · PHONE SCREENByteDance interview questions
  • Greedy Person-Cake Matching DistanceSnowflake · PHONE SCREENSnowflake interview questions
  • Defer Expenses to Preserve BalanceDRW · PHONE SCREENDRW interview questions
  • Minimum Operations to Make Every Array Element OneOtter.ai · PHONE SCREENOtter.ai interview questions
  • Maximize Adjacent Difference With One ReversalAmazon · PHONE SCREEN
  • Minimize Array Sum After K Halving OperationsDocuSign · PHONE SCREENDocuSign interview questions
  • IPOTekion · PHONE SCREENTekion interview questions
  • Automation Pipeline, Part 3: Stage DurationPlaid · PHONE SCREENPlaid interview questions

Interview reports that mention this question

  • Adobe New Grad MTS Interview Questions: 7 Experiences

Adobe interview experiences

  • Adobe Web, QA, DevOps, ML Roles: 13 Experiences (Part 3 of 3)
  • Adobe SWE Interviews, Level Unknown: 25 Experiences (Part 2 of 3)
  • Adobe Interviews, Level Unknown: 38 Experiences (Part 1 of 3)
  • Adobe ML/Research Intern Interviews: 12 Experiences (Part 4 of 4)
  • Adobe Product Intern Interviews: 15 Experiences (Part 3 of 4)
All Adobe interview questionsSee Adobe hiring insights
Saved
class Solution {
    public int minHalvings(double[] nums, double k) {
        // Write your code here.
    }
}
Checking account…