Data Structures & AlgorithmsModerateTCS NQT · Accenture
Problem: Start at 1 and apply the rules: multiply by 3 if the number is even, add 5 if it is odd. Apply 9 steps. What is the final value?
- A. 13122
- B. 118098
- C. 39366
- D. 19683
Correct answer: C. 39366
1 is odd so it becomes 6; from then on every value is even and is tripled, so after 9 steps the value is 6 · 3⁸ = 39366. Stopping after 8 steps gives 13122, doing 10 steps gives 118098, and swapping the rules (×3 when odd) gives 3⁹ = 19683.
More Coding Interview Problems questions
- Problem: The stream of numbers 3, 8, 2, 9, 4, 7, 6, 1 is processed by a running median: after each number, the median of the numbers so…
- Problem: A sequence is defined by a1 = 1, a2 = 1, and an = an−1 + an−2 mod 7 for n ≥ 3. What is a30 (1-indexed)?
- Problem: A grid of size 3×4 has the cell values 1 to 12 filled row-wise. Starting at the top-left (value 1), you may move right or down…
- For a = [2, -1, 4, -3, 5], which of the following statements is TRUE? A. Some contiguous subarray sums to 7. B. Every prefix sum from the…
- What does this program print? python a = [1, -1, 2, -2, 3] seen = {0: 0} s = 0; out = [] for i, x in enumerate(a, 1): s += x if s in seen…
- What does this program print? python best = None s = 0 for x in [4, -2, -2, 3, -1]: s += x best = s if best is None else max(best, s)…