FastPrepSet and Clear Bits
Problems/Set and Clear Bits

Set and Clear Bits

AMD logoAMD● EasyNEW GRADPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: The interviewer asked for simple code to set bits to 1 and clear them to 0. The report omits the word width, bit numbering and API. This exercise uses an unsigned 32-bit word and an ordered batch of single-bit operations. Approximate source match: 80%.

Start with the unsigned 32-bit word value. Process each row of operations in order. A row [0, bit] sets that bit to 1; a row [1, bit] clears it to 0. Bit 0 is the least significant bit and bit 31 is the most significant bit. Other bits do not change.

Return the unsigned numeric value after each operation. Setting a bit that is already 1 and clearing a bit that is already 0 leave the word unchanged. Use a wide integer for the input and results so that values above the signed 32-bit maximum stay positive.

Function

updateBits(value: long, operations: int[][]) → long[]

Examples

Example 1

value = 5operations = [[0,1],[1,2],[0,1]]return = [7,3,3]

The word starts as binary 101. Setting bit 1 gives 111, clearing bit 2 gives 011, and setting bit 1 again leaves 3.

Example 2

value = 0operations = [[0,31],[1,31]]return = [2147483648,0]

Setting the highest bit produces the positive unsigned value 2147483648. Clearing it returns to 0.

Example 3

value = 8operations = []return = []

There are no operations, so there are no reported intermediate values.

Constraints

  • 0 <= value <= 4294967295.
  • 0 <= operations.length <= 10000.
  • Every operation has exactly two integers: its type is 0 or 1 and its bit index is from 0 through 31.

More AMD problems

  • Insert After a Linked-List NodeONSITE INTERVIEW · Seen Oct 2026
  • LRU CacheONSITE INTERVIEW · Seen Oct 2026
  • Lowest Common Ancestor of a Binary TreePHONE SCREEN · Seen Oct 2026
All AMD interview questionsSee AMD hiring insights
Saved
public long[] updateBits(long value, int[][] operations) {
    return new long[0];
}
Checking account…