Data Structures & AlgorithmsModerateTCS NQT Digital · Accenture
Problem: A string is built by writing the first 15 positive integers in binary, concatenated in order (1, 10, 11, 100, ..., 1111). How many '1' characters appear in the first 40 characters of this string?
- A. 32
- B. 25
- C. 16
- D. 24
Correct answer: D. 24
Numbers 1..7 take 17 characters and 8..12 take 20 more, so the first 40 characters are 1..12 (22 ones) plus '110' from 13 = 1101, giving 24. Counting the whole 49-character string gives 32, reading 41 characters gives 25, and counting zeros gives 16.
More Coding Interview Problems questions
- Problem: A sorted array [1, 3, 3, 5, 8, 8, 8, 13, 21] is searched for the value 8 using the standard lower-bound binary search (find the…
- Problem: A tree has 7 nodes 1–7 with edges 1-2, 1-3, 2-4, 2-5, 3-6, 6-7. Each node is coloured red if its depth from node 1 is even and…
- Problem: Starting with the sorted list 1, 4, 9, 16, 25, 36, two operations alternate: first remove the largest element, then append the…
- Problem: A simple graph has 6 vertices labelled 1–6. Vertex i is adjacent to j exactly when gcd(i, j) = 1 and i ≠ j. How many edges does…
- Problem: What is the number of inversions in the array [6, 2, 8, 1, 9, 4, 3, 7, 5]? (An inversion is a pair of indices i < j with a[i] >…
- Problem: Using a single counter, a sequence of commands is applied to the value x = 0: "+5", "×2", "−3", "×2", "+1", "÷4" (integer…