Data Structures & AlgorithmsModerateTCS NQT · Codeforces Div2 B
What is the minimum number of characters you must delete from "aaabbbbcccccdd" so that no three equal letters are consecutive?
- A. 8
- B. 6
- C. 10
- D. 5
Correct answer: B. 6
Each maximal run of length L must shrink to at most 2, costing max(0, L − 2) deletions, and runs are independent. Deleting every letter that repeats the previous letter removes too many.
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 subsets of {1, 2, ..., 8} have a sum divisible by 4?
- How many contiguous subarrays of [3, 1, 4, 1, 5, 2] have their FIRST element as their maximum (ties count as maximum)?
- What is the length of the longest subsequence (any positions, keeping order) of [2, 3, 5, 1, 4] whose product is at most 12?
- How many non-empty subsets of [1, 2, 3, 4, 5, 6, 7] (chosen by position) have a sum that is a perfect square?
- How many non-empty subsets of [2, 4, 6, 8, 10, 12, 3] (chosen by position) have a sum of exactly 25?
- The numbers 1, 2, 3, 4, 5 are pushed onto an initially empty stack in this order, and pops may be interleaved with pushes at any time…