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?
- A. 2
- B. 1
- C. 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
- Problem: How many distinct values does x XOR y take over pairs of distinct elements of [1, 2, 3]? Run the code. python from itertools…
- Problem: What does the following print? It sums the entries at even positions of the array sorted in descending order. python a = [5, 1…
- Problem: What is the maximum sum of non-adjacent elements of [3, 2, 7, 10]? Run the DP. python a = [3, 2, 7, 10] inc = exc = 0 for x in a…
- Problem: How many ways tile a 1 x 4 strip with 1 x 1 squares and 1 x 2 dominoes? Run the code. python f = [1, 1] for in range(3)…
- Problem: How many trailing zero bits does 40 have in binary? Run the code. python print((40 & -40).bitlength() - 1) What is printed?
- Problem: How many pairs (i < j) of [2, 4, 6, 8] have gcd exactly 2? Run the code. python from itertools import combinations from math…