Data Structures & AlgorithmsModerateTCS NQT · Infosys
Problem: Starting from x = 7, apply six times the rule: if x is even, x = x/2 (integer), otherwise x = 2x + 3. What is the final value of x?
- A. 317
- B. 637
- C. 1277
- D. 511
Correct answer: B. 637
2x + 3 is always odd, so all six steps use it: 7, 17, 37, 77, 157, 317, 637. Five steps give 317, seven give 1277, and using 2x + 1 gives 511.
More Coding Interview Problems questions
- Problem: The words of "the sky is blue" are put in reverse order and joined by single spaces to form a new string. How many characters…
- Problem: The array [1, 2, 3, 4, 5, 6, 7, 8] is rotated left by 3 and then the first 4 elements are reversed. What is the element at index…
- Problem: The string "abcdefgh" is cut into pieces of length 3 from the left (the last piece may be shorter). The pieces are then sorted…
- Problem: Let g(n) be the number of integers in [1, n] whose decimal digit sum is even. What is g(50)?
- Problem: The Euler's totient of 36 is φ(36), the count of integers in [1, 36] coprime to 36. What is φ(36)?
- Problem: A pair of ropes is connected as a chain: lengths 3, 4, 5 are joined in the order listed, each join costs the sum of the two…