Data Structures & AlgorithmsModerateTCS NQT · Infosys
Problem: Count the substrings of length 3 in "xyzzaz" that contain three distinct characters.
- A. 2
- B. 0
- C. 3
- D. 1
Correct answer: D. 1
Check each window of length 3 for distinct letters. Counting windows where the first and last letters differ is a looser condition.
More Coding Interview Problems questions
- Problem: Min-cost climbing: cost = [10, 15, 20, 5, 1]. You may start at index 0 or 1, and from index i you can pay cost[i] to move up 1 or…
- Problem: Count the sequences of steps from {1, 2, 5} that sum to exactly 10 (the order of steps matters).
- Problem: A robot starts at (0, 0) facing north on an unbounded grid. Instructions: 'G' moves one step forward; 'L' turns 90° left; 'R'…
- Problem: Elevator starts at floor 0. Requests arrive in order for floors 3, 1, 4 (the elevator serves each request by going directly to…
- Problem: A traffic light cycles green for 30 s, then yellow for 5 s, then red for 25 s, starting at time 0 with green. How many whole…
- Problem: A water-jug problem: a 3-litre jug and a 5-litre jug, both empty, and unlimited water. Allowed actions: fill a jug fully, empty a…