Data Structures & AlgorithmsVery hardGATE CS · TCS NQT
Repeatedly remove adjacent equal characters from "abbaca" using a stack. How many characters are removed in total?
- A. 5
- B. 4
- C. 2
- D. 6
Correct answer: B. 4
A stack that pops on a match performs the reductions in one pass; the final string is "ca", so 4 characters are removed.
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 integers n from 1 to 99 inclusive have both n and n + 1 squarefree (not divisible by any square greater than 1)?
- Choose the fewest intervals of length 3 (covering integer points s, s+1, s+2 for a start s from 1 to 8) so that every integer point from 1…
- How many integers x with 1 ≤ x ≤ 2024 have NO two equal adjacent digits in their decimal representation?
- How many integers x with 1 ≤ x ≤ 500 have a decimal digit sum divisible by 3?
- You may swap the digits at exactly one pair of positions in the number 98368 (at most once). What is the largest number you can obtain?
- Children need greed factors [1, 2, 3, 5, 7]. Each child can receive at most one cookie, and a child is satisfied if the cookie size is at…