Data Structures & AlgorithmsModerateTCS NQT · Accenture

Problem: What is the length of the longest substring of "abcabcbb" with all characters distinct?

  1. A. 3
  2. B. 4
  3. C. 2
  4. 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

Exams that ask this topic