Data Structures & AlgorithmsHardFlipkart/Uber OA · placement

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

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

Correct answer: C. 5

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 5. 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