Data Structures & AlgorithmsModerateTCS NQT · Accenture
Problem: Starting from the empty binary string, the value of the string "1011" read in base 2 is computed, then 3 is added. What is the result?
- A. 1014
- B. 16
- C. 11
- D. 14
Correct answer: D. 14
1011₂ = 8 + 2 + 1 = 11, plus 3 is 14. Reading the string in base 10 gives 1014, reading it backwards (1101₂ = 13) gives 16, and 11 forgets to add 3.
More Coding Interview Problems questions
- Problem: A list is [5, 9, 2, 7]. How many pairs (i, j) with i < j have a[i] + a[j] greater than 10?
- Problem: For the words ["sleep", "steep", "sheep", "creep"] (all of length five), how many unordered pairs differ in exactly one letter…
- Problem: The string "abcabc" is processed by replacing each character with its index in the alphabet (a=0, b=1, ..., z=25), and then the…
- Problem: A directed graph on vertices 0–4 has arcs 0→1 (2), 0→2 (6), 1→2 (3), 1→3 (9), 2→3 (1), 3→4 (2), 2→4 (8). What is the length of…
- Problem: Vertices 1–6 of an undirected graph have edges 1-2, 2-3, 4-5, 5-6, 6-4 and 3-1. How many edges are NOT part of any cycle?
- Problem: A rooted tree (root 1) has children 1: [2, 3], 2: [4], 3: [5, 6], 5: [7]. What is the number of nodes at depth 2 (root at depth 0)?