Data Structures & AlgorithmsModerateTCS NQT Digital · Infosys
Problem: A sequence of 10 operations applies to an initial value of 0: operation i (1 ≤ i ≤ 10) adds i if i is odd and multiplies the current value by 2 modulo 1000 if i is even. What is the final value?
- A. 114
- B. 83
- C. 166
- D. 55
Correct answer: C. 166
Values run 1, 2, 5, 10, 15, 30, 37, 74, 83, 166. Swapping the parity rule gives 114, numbering the operations from 0 (or stopping at 9) gives 83, and 55 just adds 1..10.
More Coding Interview Problems questions
- Problem: A graph's adjacency list is 0: [1, 2], 1: [3], 2: [3, 4], 3: [5], 4: [5], 5: []. What is the number of distinct topological…
- Problem: The number of integers from 1 to 100 that have exactly three divisors is what value? (Numbers with exactly three divisors are…
- Problem: What is the number of inversions in the array [4, 3, 2, 1, 0]?
- Problem: The string "cabbage" is sorted by letter using a stable sort on the letters only. What is the 4th character of the sorted string?
- Problem: Starting with 1, the operations are: multiply by 2, then add 3, applied three times in a row (x → 2x + 3). What is the result…
- Problem: Find the number of integers n in the range 2 to 100 for which n and n + 2 are both prime (twin primes, counted by the smaller…