Data Structures & AlgorithmsModerateCodeforces Div2 B · string round
Problem: What is the lexicographically smallest rotation of 'bcabca'?
Problem: What is the lexicographically smallest rotation of 'bcabca'?
s = 'bcabca' print(min(s[i:] + s[:i] for i in range(len(s))))What is printed?
- A. bcabca
- B. cabcab
- C. abcabc
- D. abcab
Correct answer: C. abcabc
The rotation starting at the first 'a' is abcabc, and it is the smallest of all six rotations. Printing the original string is the trap for those who forget to rotate.
More Coding Interview Problems questions
- Problem: Items (weight, value) are (2,3), (3,4), (4,5), and each may be used at most once. Capacity W = 7. Run the code below to find the…
- Problem: How many ways can a staircase of 8 steps be climbed if each move climbs 1, 3 or 4 steps? Run the DP below. python ways = [0] 9…
- Problem: Jobs are given as (deadline, profit): (2,100), (1,19), (2,27), (1,25), (3,15). Each job takes one unit slot and must finish by…
- Problem: Compute C(10, 3) mod 7 using Lucas' theorem, where 7 is prime. What is the result?
- Problem: What is 3^100 mod 10?
- Problem: How many positive divisors does 2^4 3^2 5 7 have?