Data Structures & AlgorithmsModerateTCS NQT · sliding window

Problem: What is the largest number of distinct characters in any window of length 3 of 'abcabc'? Run the code.

Problem: What is the largest number of distinct characters in any window of length 3 of 'abcabc'? Run the code.
s = 'abcabc'
print(max(len(set(s[i:i + 3])) for i in range(len(s) - 2)))
What is printed?
  1. A. 2
  2. B. 1
  3. C. 4
  4. D. 3

Correct answer: D. 3

Every window of length 3 in 'abcabc' is a permutation of a, b and c, so the maximum distinct count is 3.

More Coding Interview Problems questions

Exams that ask this topic