FastPrepMinimum Power-of-Two Removal Operations
Problems/Minimum Power-of-Two Removal Operations

Minimum Power-of-Two Removal Operations

IBM logoIBM● MediumFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A community report says this exactly matches the power-of-two removal task, in an IBM online assessment. The original IBM wording and screenshots were not given. The number limits, the examples and the function signature are our choices. Our version is about 95% the same as the referenced task.

Special thanks: 🌷 A special thank you to a lovely, amazing fren who shared that this question appeared again on October 14, 2026! ( ᴗ͈ˬᴗ͈)ഒ 💜

You are given an array arr of nonnegative integer exponents. Each element arr[i] represents the value 2^arr[i].

In one operation, select a nonempty group of remaining elements and remove them. The operation is allowed only if the sum of their represented values is exactly 2^p for some integer p >= 0.

  • You may select elements from any positions; they do not need to be consecutive.
  • Each element can be removed only once.
  • The exponent p may differ between operations and may exceed the largest exponent in the input.

Return the minimum number of operations needed to remove all elements.

Function

findMinOperations(arr: int[]) → int

Examples

Example 1

arr = [0,0,1,2]return = 1

Remove all four elements together: 2^0 + 2^0 + 2^1 + 2^2 = 1 + 1 + 2 + 4 = 8 = 2^3. A nonempty array needs at least one operation, so the minimum is 1.

Example 2

arr = [0,2,2]return = 2

Remove the two elements with exponent 2 together, since 4 + 4 = 8. Then remove the element with exponent 0. One operation is impossible because the total 9 is not a power of two, so the minimum is 2.

Example 3

arr = [0,1,4]return = 3

The represented values are 1, 2, and 16. No group containing two or more of them sums to a power of two, so each must be removed separately.

Constraints

  • For this exercise, assume 1 <= arr.length <= 10^5.
  • For this exercise, assume 0 <= arr[i] <= 10^6.
  • Every element is an integer exponent, and the input order imposes no restriction on a removal group.

More IBM Online Assessment questions

  • Missing IntervalsOA · Seen Nov 2026
  • Last Object Exit TimeOA · Seen Nov 2026
  • Count Peaks and ValleysOA · Seen Nov 2026
  • Count Strictly Increasing Contiguous WindowsOA · Seen Nov 2026
  • Total Each Letter's Count in an Encoded StringOA · Seen Nov 2026
  • Count Servers With No Requests in a Time WindowOA · Seen Nov 2026
  • Maximum Easy Tasks After RearrangingOA · Seen Nov 2026
  • Tree Pythagorean TriplesOA · Seen Oct 2026
  • Maximum Compatible Time WindowsOA · Seen Oct 2026
  • Query Type Frequency WindowOA · Seen Oct 2026

Similar questions at other companies

  • Count Subarrays with a Perfect-Square ProductMicrosoft · OAMicrosoft interview questions
  • Repeated Mirror XORMathWorks · OAMathWorks interview questions
  • Minimum Power-of-Two Removal OperationsVisa · OAVisa interview questions
  • Find the Missing Number from 1 to nGEP · OA
  • Bayesian Scenario ClassifierAmazon · ONSITE INTERVIEW
  • Find the Missing Number from 1 to nHyperVerge · ONSITE INTERVIEW
  • Last Object to Fall Off the TableConfluent · OAConfluent interview questions
  • Minimum Rounds to Complete All TasksInfosys · OAInfosys interview questions
  • Capping Portfolio WeightsCapstone Investment Advisors · OA
  • Knights, Knaves and Their StatementsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions

IBM interview experiences

  • IBM Full-Time SWE OA Questions: 1 Experience
  • IBM Software Intern Résumé Rounds: 2 Experiences (Part 3 of 3)
  • IBM Intern Blitz Interviews: 23 Experiences (Part 2 of 3)
  • IBM Software Intern Interviews: 44 Experiences (Part 1 of 3)
  • IBM Software Intern Interview Questions: 15 Experiences
All IBM interview questionsSee IBM hiring insights
Saved
class Solution {
    public int findMinOperations(int[] arr) {
        // Write your code here.
    }

}
Checking account…