← Quiz: String Matching — KMP and Rabin-Karp: all 10 questions
Quiz: String Matching — KMP and Rabin-Karp · Question 8 of 10
What does this print? (code)
What does this print?
text, m = "4567", 2
h = int(text[:m])
values = [h]
for i in range(1, len(text) - m + 1):
h = (h - int(text[i - 1]) * 10) * 10 + int(text[i + m - 1])
values.append(h)
print(values)
- A.[45, 56, 67]
- B.[45, 46, 47]
- C.[4, 5, 6]
- D.[45, 560, 670]
Answer & explanation
Correct answer: [45, 56, 67]
Each step removes the first digit's tens and adds the next digit: 45 → 56 → 67.
Can you get the rest right without peeking?
Take the timed Quiz: String Matching — KMP and Rabin-Karp quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →