Data Structures & AlgorithmsModerateTCS NQT Digital · Accenture
Problem: Starting with the number 1, double it and add 1 repeatedly. What is the value after the 10th doubling step (starting value 1, 10 operations)?
- A. 2047
- B. 1023
- C. 4095
- D. 1024
Correct answer: A. 2047
x → 2x + 1 from 1 gives 2^(k+1) − 1 after k steps, so 2¹¹ − 1 = 2047 after 10. Nine steps give 1023, eleven give 4095, and 2¹⁰ = 1024 forgets the + 1s.
More Coding Interview Problems questions
- Problem: The array [2, 4, 3, 1, 6, 5] is partitioned into the largest possible number of consecutive chunks such that after sorting each…
- Problem: A string of length 4 over {0, 1} has an even number of 1s. How many such strings are palindromes?
- Problem: The product 2^3 · 3^2 · 5^1 · 7^2 has how many positive divisors?
- Problem: For the array [1, 3, 5, 7, 9], how many subarrays have an average equal to 5?
- Problem: The string "aabbccdd" has all its letters doubled. How many substrings of length 2 consist of two identical letters?
- Problem: A 2×4 grid has a wall at (0,2) (row, column, 0-indexed); all other cells are open. Moves go up, down, left or right. What is the…