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?

  1. A. 114
  2. B. 83
  3. C. 166
  4. 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

Exams that ask this topic