CodeSignal Technical Assessment Bit Manipulation and Mathematical Reasoning 2 — Questions and Answers
Question 1: To find the single non-repeating element in an array where every other element appears exactly twice, which operation is applied across all elements?
- AND all elements
- OR all elements
- XOR all elements (Correct answer)
- NOT all elements
Correct answer: XOR all elements
XOR of any number with itself is 0, so paired elements cancel out and the unique element remains.
Question 2: What is the GCD of 48 and 18?
- 3
- 6 (Correct answer)
- 9
- 12
Correct answer: 6
Applying the Euclidean algorithm: gcd(48,18)=gcd(18,12)=gcd(12,6)=gcd(6,0)=6.
Question 3: How many set bits does the number 12 (binary 1100) have?
- 1
- 2 (Correct answer)
- 3
- 4
Correct answer: 2
12 in binary is 1100, which has exactly two 1-bits.
Question 4: What is `~0` in a 32-bit two's complement integer system?
- 0
- 1
- -1 (Correct answer)
- 2147483647
Correct answer: -1
Bitwise NOT of 0 flips all 32 bits to 1, which represents -1 in two's complement encoding.
Question 5: What is (7 × 8) mod 5?
- 1 (Correct answer)
- 2
- 3
- 6
Correct answer: 1
7 × 8 = 56, and 56 mod 5 = 1 because 56 = 11 × 5 + 1.
Question 6: What does arithmetic right shift of -8 by 1 typically produce in most languages?
- -4 (Correct answer)
- -16
- 4
- 0
Correct answer: -4
Arithmetic right shift preserves the sign bit, so -8 >> 1 = -4, equivalent to floor division by 2.
To find the single non-repeating element in an array where every other element appears exactly twice, which operation is applied across all elements?