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?
- A. 4
- B. 2
- C. 3
- 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
- Problem: How many ways are there to tile a 2 x 6 board with 2 x 1 dominoes? Run the DP. python f = [1, 1] for n in range(2, 7)…
- Problem: What is the minimum number of edges to remove from a 5-vertex complete graph to leave a spanning tree? Run the code (answer = E…
- Problem: How many integers from 1 to 10^6 have exactly one set bit (power of two)? Run the code. python print(sum(1 for x in range(1, 10 6…
- Problem: What is the maximum number of points on a line among (0,0), (1,1), (2,2), (3,5), (4,4) (collinear with the diagonal)? Run the…
- Problem: What is the time complexity of the Hopcroft-Karp algorithm for maximum matching on V vertices and E edges?
- Problem: Which technique gives the answer to 'minimum number of platforms' by sorting events?