Data Structures & AlgorithmsModerateTCS NQT Digital · Infosys
Problem: Starting with the list [1, 2, 3, 4, 5, 6], repeatedly remove every second element (keeping the first) until one element remains. Which value is left?
- A. 2
- B. 1
- C. 0
- D. 3
Correct answer: B. 1
Each pass keeps the odd positions (indices 0, 2, 4, ...). The survivor is the value at index 0 at the end, and the parity of each list length determines the path.
More Coding Interview Problems questions
- Problem: In the array [5, 1, 4, 2, 8, 0, 2], count the pairs (i, j) with i < j and a[i] > 2·a[j] (so a[i] is more than double a[j]).
- Problem: The string "aabcbbca" is processed by a sliding window that keeps at most one distinct letter 'a' inside (other letters are…
- Problem: How many integers in [1, 200] are divisible by exactly one of 6 and 8?
- Problem: The Euler's criterion test: count the quadratic residues modulo 13 among 1 through 12 (a residue r satisfies x² ≡ r for some…
- Problem: How many 4-digit numbers (1000 to 9999) have all four digits distinct and in strictly decreasing order from left to right?
- Problem: Compute the sum of the digits of the number 2^20 × 5^18 written in decimal.