Data Structures & AlgorithmsModerateTCS NQT Digital · Infosys
Problem: A sequence is generated from 1 by repeatedly applying: x → x + (x mod 4). Starting at x = 1, what is the value after 6 steps?
- A. 5
- B. 3
- C. 4
- D. 6
Correct answer: C. 4
Iterate the map six times: 1 → 2 → 4 → 4 → 4 ... since x mod 4 = 0 once x = 4 the value stalls. Tracking the stall correctly gives the final value.
More Coding Interview Problems questions
- Problem: An array of length 7 holds the values 0 to 6 in some order; the position of value k is pos[k]. For the array [2, 0, 3, 6, 1, 5…
- Problem: From the string "3a7b2c" the digits are extracted and summed. What is the sum of the digits?
- Problem: The number of ways to place 3 identical red balls and 2 identical blue balls in a row of 5 positions is what value?
- Problem: The matrix [[1,2],[3,4]] is raised to the power 3 (matrix multiplication, not element-wise). What is the entry in row 0, column 0…
- 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…
- Problem: A list is [5, 9, 2, 7]. How many pairs (i, j) with i < j have a[i] + a[j] greater than 10?