Data Structures & AlgorithmsModerateProduct-company MCQ pattern

Using a sliding window, find the length of the longest substring with no repeated character in the string dvdfabcda.

  1. A. 9
  2. B. 4
  3. C. 6
  4. D. 3

Correct answer: C. 6

The window vdfabc (positions 1–6) has 6 distinct letters; when d arrives the left edge jumps past the earlier d and the window shrinks to fabcd. 4 is the size of the final window (forgetting to keep the maximum), 9 is the whole string and 3 stops at the first repeat (dvd).

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic