Data Structures & AlgorithmsHardAccenture · TCS NQT Digital
Problem: What is the length of the longest substring of "eceebaabbccbdeeabe" that contains at most 2 distinct characters?
- A. 5
- B. 6
- C. 4
- D. 7
Correct answer: A. 5
A sliding window with letter counts shrinks from the left only while more than two distinct letters are inside. Forgetting to delete zero-count letters makes the distinct-count test wrong.
More Coding Interview Problems questions
- Problem: Find the lexicographically smallest rotation of the string "dcbadcb". What is its starting index (0-based) in the original…
- Problem: The longest common subsequence of "ABCBDAB" and "BDCABA" has length L. What is L?
- Problem: From the string "aaabbbaabbccaa", you may delete the minimum number of characters so that no two adjacent characters are equal…
- 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…