← Quiz: String Matching — KMP and Rabin-Karp: all 10 questions
Quiz: String Matching — KMP and Rabin-Karp · Question 6 of 10
What does this print? (code)
What does this print?
text, pat = "abababa", "aba"
print([i for i in range(len(text) - len(pat) + 1) if text[i:i + len(pat)] == pat])
- A.[0, 4]
- B.[0]
- C.[0, 2, 4]
- D.[0, 1, 2, 3, 4]
Answer & explanation
Correct answer: [0, 2, 4]
Matches may overlap: "aba" starts at 0, 2 and 4.
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 →