Data Structures & AlgorithmsModerateTCS NQT · Accenture
Problem: What is the length of the longest substring of "abcabcbb" with all characters distinct?
- A. 3
- B. 4
- C. 2
- D. 5
Correct answer: A. 3
Expand from each start until a repeated character appears; the longest such run is the answer. Measuring the total number of distinct characters in the string instead gives a different number.
More Coding Interview Problems questions
- Problem: The shortest palindrome obtainable by inserting characters only at the front of "abacd" has what length?
- Problem: How many distinct palindromic substrings does "abacaba" contain (single characters count as palindromes, and distinct strings…
- Problem: Among all distinct permutations of the letters A, B, C, D, arranged in dictionary order starting from rank 1, what is the rank of…
- Problem: For the words ["flowchart", "flow", "flight", "flower"], what is the length of their longest common prefix?
- Problem: In the string "abciiidef", what is the maximum number of vowels (a, e, i, o, u) in any contiguous substring of length 4?
- Problem: What is the minimum number of insertions plus deletions needed to convert "heap" into "pea" if only insertions and deletions are…