Data Structures & AlgorithmsModerateTCS NQT · Accenture

Problem: The string "abcabcbb" is scanned and for each position the length of the longest run of distinct characters starting at that position is recorded. What is the maximum of these recorded lengths?

  1. A. 4
  2. B. 2
  3. C. 3
  4. D. 5

Correct answer: C. 3

Starting from each index and extending until a repeat gives each run; the maximum equals the longest substring with distinct characters. Recording the run from the first index alone gives a shorter value.

More Coding Interview Problems questions

Exams that ask this topic