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?

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

Exams that ask this topic