Data Structures & AlgorithmsModerateTCS NQT · Infosys
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 2). After it, what is the element at index 1?
- A. 5
- B. 6
- C. 4
- D. 7
Correct answer: A. 5
deque.rotate(n) with positive n moves elements from the right end to the left, so the deque becomes 4, 5, 1, 2, 3. Rotating left instead gives a different index-1 element.
More Coding Interview Problems questions
- 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.
- Problem: Compute C(20, 10) modulo 1,000,000,007 (the binomial coefficient).
- Problem: How many prime numbers are there up to 100 (inclusive)?