Data Structures & AlgorithmsModerateProduct Company SDE · CP practice

Problem: What is the maximum number of distinct characters in a substring of length 4 of 'abcabcabc'? Run the code.

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

Correct answer: C. 3

Any length-4 window of the repeating 'abc' pattern contains exactly three distinct letters.

More Coding Interview Problems questions

Exams that ask this topic