Data Structures & AlgorithmsHardICPC regional · Codeforces Div2 B

Problem: In Python, what is the value of (−5 >> 1) + 10, where >> is the arithmetic right shift applied to the negative integer −5?

  1. A. 8
  2. B. 7.5
  3. C. 7
  4. D. 12

Correct answer: C. 7

Python's >> on negatives is floor division by 2, so −5 >> 1 = −3 and the result is 7. Truncating toward zero like C's −5 / 2 gives −2 and 8, true division gives −2.5 and 7.5, and shifting 5 instead of −5 gives 12.

More Coding Interview Problems questions

Exams that ask this topic