Data Structures & AlgorithmsModerateTCS NQT · Infosys

Problem: The string "abcdabcd" is examined for windows of length 4 with all four characters distinct. How many such windows are there?

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

Correct answer: A. 5

Check each length-4 window for distinct letters with a set. Counting distinct windows as strings gives a smaller number because some windows repeat.

More Coding Interview Problems questions

Exams that ask this topic