Data Structures & AlgorithmsHardTCS NQT · Accenture
Problem: The string "aabcbbca" is processed by a sliding window that keeps at most one distinct letter 'a' inside (other letters are allowed only outside). What is the longest substring containing at most one 'b' and any number of other letters?
- A. 5
- B. 3
- C. 6
- D. 4
Correct answer: D. 4
The window shrinks from the left only when a second 'b' enters, which keeps the invariant. Ignoring the left-side shrink grows the window past the allowed count.
More Coding Interview Problems questions
- Problem: How many integers in [1, 200] are divisible by exactly one of 6 and 8?
- Problem: The Euler's criterion test: count the quadratic residues modulo 13 among 1 through 12 (a residue r satisfies x² ≡ r for some…
- Problem: How many 4-digit numbers (1000 to 9999) have all four digits distinct and in strictly decreasing order from left to right?
- Problem: Compute the sum of the digits of the number 2^20 × 5^18 written in decimal.
- Problem: Let f(n) = number of 1-bits in n. Compute Σ f(n) for n from 0 to 63 inclusive.
- Problem: Starting at (0,0), the robot moves in the string "NNEESSWWNE" with N = up, E = right, S = down, W = left. Count the number of…