Data Structures & AlgorithmsModerateTCS NQT · Infosys

A text cursor starts after the text abc (cursor at the end). Operations in order: type x, Left, Left, Backspace, Right, type y. Here Left and Right move the cursor one character, and Backspace deletes the character before the cursor. What is the length of the final text?

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

Correct answer: A. 4

Simulate the cursor position explicitly: typed characters go in at the cursor, not at the end. The text becomes abcx, then acx, then acyx, so its length is 4.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic