Data Structures & AlgorithmsVery hardTCS NQT Digital · Product Company SDE
Problem: A list starts as [1, 2, 3, 4, 5, 6, 7, 8]. Four operations are applied in order: rotate the list left by 3; reverse the first 4 elements; rotate right by 2; swap elements at indices 0 and 7. What is the element at index 2 of the final list?
- A. 2
- B. 3
- C. 7
- D. 6
Correct answer: C. 7
Rotate left 3 → [4,5,6,7,8,1,2,3]; reverse first 4 → [7,6,5,4,8,1,2,3]; rotate right 2 → [2,3,7,6,5,4,8,1]; swap ends → [1,3,7,6,5,4,8,2], so index 2 holds 7. Rotating in the opposite directions gives 2, and reading 1-based index 2 gives 3 while reading index 3 gives 6.
More Coding Interview Problems questions
- Problem: XOR of all integers from l = 13 to r = 46 inclusive. Compute the result.
- Problem: The number of trailing zeros of 500! written in base 6 (i.e., how many times 6 divides 500!) is what value?
- Problem: A 5×5 grid has 1s and 0s: 11000 / 11011 / 00100 / 01100 / 10001 (rows top to bottom). You may flip exactly one 0 into a 1. What…
- Problem: A DAG with vertices 0–5 has weighted edges 0→1 (2), 0→2 (1), 1→3 (2), 2→3 (3), 2→4 (1), 3→5 (1), 4→5 (5). How many distinct…
- Problem: An undirected connected graph has 9 vertices and 13 edges. What is the cyclomatic number (the number of independent cycles…
- Problem: An undirected graph on 7 vertices (0–6) has degrees 0:3, 1:2, 2:4, 3:1, 4:2, 5:3, 6:1. How many vertices have odd degree? (Such a…