FastPrepMinimum Power-of-Two Adjustments
Problems/Minimum Power-of-Two Adjustments

Minimum Power-of-Two Adjustments

NVIDIA logoNVIDIA● MediumFULLTIMEOA

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Based on an NVIDIA HackerRank OA report with the same operation and three examples. The source author recalls a 1 through 2^16 bound in a reply; this practice adopts that bound and specifies nonnegative intermediate values. Approximate source match: 95%.

Given a positive integer n, return the minimum number of operations needed to reduce it to zero. In one operation, add or subtract 2^i for any integer i >= 0. Each addition or subtraction costs one operation.

For this exercise, intermediate values are nonnegative and may exceed the starting value. Removing factors of two in an algorithm is a reasoning step, not an allowed free operation on the actual number.

Function

minPowerAdjustments(n: int) → int

Examples

Example 1

n = 14return = 2

Add 2 to obtain 16, then subtract 16.

Example 2

n = 27return = 3

Add 4 to obtain 31, add 1 to obtain 32, then subtract 32.

Example 3

n = 1return = 1

Subtract 1 to reach zero.

Constraints

  • 1 <= n <= 65536.
  • Use integer arithmetic; powers may exceed n.

More NVIDIA Online Assessment questions

  • Query a Header-Encoded MatrixOA · Seen Oct 2026
  • Maximum ScoreOA · Seen Oct 2026
  • Address on Same PageOA · Seen Oct 2026
  • Minimize Task Resource ConsumptionOA · Seen Oct 2026
  • Minimum Project Bid CostOA · Seen Oct 2026
  • Count Ideal Numbers in a RangeOA · Seen Oct 2026
  • Generate Bit MaskOA · Seen Oct 2026
  • Reconstruct an Array from Prefix XOROA · Seen Oct 2026
  • Sum of Subarray MinimumsOA · Seen Oct 2026
  • Unique Integers That Sum to ZeroOA · Seen Oct 2026

Similar questions at other companies

  • Minimum Halvings for Alternating ParityIBM · OAIBM interview questions
  • XOR MultiplicationMicrosoft · OAMicrosoft interview questions
  • Minimum Operations To Reduce To ZeroUber · OAUber interview questions
  • IP Address to CIDR BlocksOpenAI · PHONE SCREENOpenAI interview questions
  • IP Range to CIDR BlocksAirbnb · PHONE SCREENAirbnb interview questions
  • Minimum Rounds to Complete All TasksInfosys · OAInfosys interview questions
  • Server Upgrade PlanningWells Fargo · OAWells Fargo interview questions
  • Knights, Knaves and Their StatementsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
  • Minimum No-Repeat Segments After One Character RemovalSalesforce · OASalesforce interview questions
  • Repeated Mirror XORMathWorks · OAMathWorks interview questions

Interview reports that mention this question

  • NVIDIA OA: What It Tests (2026)

NVIDIA interview experiences

  • NVIDIA Full-Time SWE Onsite Scheduling: 1 Experience
  • NVIDIA DevOps, QA and Infra Intern Interviews: 12 Experiences
  • NVIDIA Ignite Internship OA Experience
  • NVIDIA Software Intern Interview Questions: 9 Experiences
  • NVIDIA Ignite SWE Intern OA Questions: 6 Experiences
All NVIDIA interview questionsSee NVIDIA hiring insights
Saved
class Solution {
    public int minPowerAdjustments(int n) {
        // Write your code here
    }
}
Checking account…