Data Structures & AlgorithmsHardTCS Digital · Infosys SP

Using a sliding window with a last-seen index map, what is the length of the longest substring of "dbdcccdcbaddad" with all characters distinct?

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

Correct answer: B. 4

When a repeat appears, move the left edge just past that character's previous occurrence (not to the current index). The best window has length 4. Restarting the window from scratch on a repeat gives 4.

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

Exams that ask this topic