Data Structures & AlgorithmsModerateProduct Company SDE · string round
Problem: Is 'cdeab' a rotation of 'abcde'? Check with the substring test below. What is printed?
Problem: Is 'cdeab' a rotation of 'abcde'? Check with the substring test below. What is printed?
s, t = 'abcde', 'cdeab' print(len(s) == len(t) and t in s + s)What is printed?
- A. False
- B. True
- C. 1
- D. None
Correct answer: B. True
'abcde' + 'abcde' contains 'cdeab' as a substring, so t is a rotation of s. Checking only t in s fails.
More Coding Interview Problems questions
- Problem: Find the minimum cost of a Hamiltonian tour starting and ending at city 0, with symmetric distances D =…
- Problem: How many ordered outcomes of three fair six-sided dice sum to 9? Run the code. python print(sum(1 for a in range(1, 7) for b in…
- Problem: What is the Pisano period of the Fibonacci sequence modulo 10 (the length after which (F(n), F(n+1)) mod 10 repeats (0, 1))? Run…
- Problem: How many 4-digit numbers (1000 to 9999) are divisible by 11? Run the code. python print(sum(1 for x in range(1000, 10000) if x %…
- Problem: How many integers in [1, 100] have decimal digits summing to exactly 10? Run the code. python print(sum(1 for x in range(1, 101)…
- Problem: What is the minimum number of bit flips needed to make the binary string '00110' non-decreasing (all 0s then all 1s)? Run the…