Data Structures & AlgorithmsHardTCS NQT · Infosys
A backspace text editor reads the string a##b#cd# where each # deletes the previous character if one exists. How many characters remain in the final text?
- A. 1
- B. 2
- C. 0
- D. 3
Correct answer: A. 1
Simulate with a stack: each letter pushes, each # pops only when the stack is non-empty. A # on an empty stack must not remove anything.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- How many non-empty contiguous subarrays of [6, 10, 15, 7] have gcd equal to 1?
- What is the sum of gcd(a[i..j]) over all contiguous subarrays of [4, 6, 8, 12]?
- How many index pairs i < j have gcd(a[i], a[j]) = 1 for the array [2, 3, 4, 5, 6, 9]?
- What is the sum of lcm(a[i], a[i+1]) for consecutive pairs of the array [2, 3, 4, 6, 9]?
- How many integers x in the range 1 to 1000 are divisible by 3 and have a digit sum divisible by 7?
- How many contiguous subarrays of [3, 4, 1, 2, 5, 6] have a sum divisible by 5?