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?
- A. 8
- B. 7.5
- C. 7
- 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
- Problem: Records (name, score) are sorted by score descending with Python's stable sort…
- Problem: A deque holds 1, 2, 3, 4, 5 from left to right. The operation rotate(2) moves the last 2 elements to the front (rotate right by…
- Problem: A 2D prefix-sum table is built for the grid [[1,2,3],[4,5,6],[7,8,9]]. What is the sum of the submatrix with rows 1–2 and columns…
- Problem: A sparse-table-free query: over the array [5, 2, 8, 1, 9, 3, 7], what is the minimum value on the range of indices [2, 5]…
- Problem: A Fenwick tree (binary indexed tree) over positions 1–8 starts with all zeros. The operations are: add 5 at position 3, add 4 at…
- Problem: Compute the 50th Fibonacci number F(50) with F(1) = F(2) = 1, modulo 1,000,000,007.