Data Structures & AlgorithmsModerateTCS NQT Digital · Infosys
Problem: The string "abcabcabc" has how many distinct substrings of length 3?
- A. 3
- B. 4
- C. 2
- D. 5
Correct answer: A. 3
The distinct length-3 substrings are abc, bca and cab, since the string is periodic with period three. Counting positions (7) overstates the distinct count.
More Coding Interview Problems questions
- Problem: What is the number of walks of length 4 that start and end at the same vertex in the complete graph K3 (vertices 0, 1, 2, each…
- Problem: How many integers in [1, 999] have digits that are strictly increasing (each digit larger than the previous)? Run the code…
- Problem: What is the sum of the first 50 terms of the sequence 1, 1, 2, 3, 5, ... (Fibonacci numbers F(1) to F(50), with F(1)=F(2)=1)? Run…
- Problem: How many pairs (i < j) of [2, 4, 6, 9, 12, 15] have gcd(ai, aj) = 3? Run the code. python from math import gcd a = [2, 4, 6, 9…
- Problem: How many integers in [1, 300] are divisible by exactly two of the numbers 2, 3 and 5? Run the code. python print(sum(1 for x in…
- Problem: What is the minimum number of perfect cubes (1, 8, 27, ...) that sum to 100? Run the DP. python INF = 10 9 dp = [0] + [INF] 100…