Data Structures & AlgorithmsModerateTCS NQT Digital · Infosys
Problem: From the string "aaabbbaabbccaa", you may delete the minimum number of characters so that no two adjacent characters are equal. How many characters must be deleted?
- A. 6
- B. 14
- C. 11
- D. 8
Correct answer: D. 8
Runs are aaa, bbb, aa, bb, cc, aa; each run keeps one letter, so deletions = 2 + 2 + 1 + 1 + 1 + 1 = 8. Counting runs gives 6, deleting every letter in a repeated run gives 14, and length minus distinct letters (14 − 3) gives 11.
More Coding Interview Problems questions
- Problem: A stack-based reduction processes the string "abbaca" from left to right: if the current character equals the top of the stack…
- Problem: Bubble sort is run on [5, 2, 9, 1, 7, 3, 8, 6, 4] using the standard adjacent-swap pass (for i from 0 to n−2, swap a[j] and…
- Problem: A list starts as [1, 2, 3, 4, 5, 6, 7, 8]. Four operations are applied in order: rotate the list left by 3; reverse the first 4…
- Problem: XOR of all integers from l = 13 to r = 46 inclusive. Compute the result.
- Problem: The number of trailing zeros of 500! written in base 6 (i.e., how many times 6 divides 500!) is what value?
- Problem: A 5×5 grid has 1s and 0s: 11000 / 11011 / 00100 / 01100 / 10001 (rows top to bottom). You may flip exactly one 0 into a 1. What…