Data Structures & AlgorithmsModerateTCS NQT · Infosys

Problem: Using a single counter, a sequence of commands is applied to the value x = 0: "+5", "×2", "−3", "×2", "+1", "÷4" (integer division, truncating toward zero), "×3", "−7". What is the final value of x?

  1. A. 3
  2. B. 2
  3. C. 1
  4. D. 4

Correct answer: B. 2

Sequential simulation with truncation toward zero for the division step. Python's floor division // gives a different result for negative intermediate values, so the sign matters here.

More Coding Interview Problems questions

Exams that ask this topic