28. Find the Index of the First Occurrence in a String - Day 3/31 Leetcode March Challenge

preview_player
Показать описание
Larry solves and analyzes this Leetcode problem as both an interviewer and an interviewee. This is a live recording of a real engineer solving a problem live - no cuts or edits!

#leetcode #coding #programming
Рекомендации по теме
Комментарии
Автор

Don't know if i'm bothered to learn this. Maybe one day.

for i in
if haystack[i:i+len(needle)] == needle:
return i
return -1

oliverheber
Автор

Don't you want to check for hash collision? In your code, you check if hash(needle) === hash(haystack_substring), but just to be safe that its an unlikely event of possible but very very very low probability collision, don't we need to manually check once that the needle does exist in that place by looping through once

senthilpalanisamy
Автор

I want to know the reasoning for choosing 20 digit prime number as when I chose 10 digit prime number it gave me wrong answer in one testcase

narolavarshil
welcome to shbcf.ru