LeetCode 1062. Longest Repeating Substring

preview_player
Показать описание

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

I really loved the Rabinkarp implementation. I struggled to make sense of Rabinkarp before watching this video. This really helped. Thank you for an excellent video

PEqualsN.P
Автор

Great Explanation. Keep it up. Thank you

shubhamkiingale
Автор

isnt mid = left + (right - left) = right?
mid = right??

natisaver
Автор

Can you post the code as well. Otherwise good video. Also don't you need to use modulus?

senthilvaithi
Автор

Hey Chang, a very good video. 42 minutes is worth it. Before this video, I was thinking of suggesting you to try to have the video under 15 minutes. (I usually watch all the video with 1.25 speed. I need to cover more stuff with the little time and attention span that I have.) More than 15 minutes tires me out since I need to code this one after watching it and need to study the another one (if the video is longer, I cannot study another problem because it has used up the time and energy). Of course, there will be exception like this video which cover three solution with progression. Well, these are my own experience and you can do what you like as a creator.

aunnfriends
Автор

class Solution(object):

# Method 4 Using binary search by a particular substring length AND USING ROLLING HASH TO OPTIMIZE THE SLICING PART IN FINDING THE SUBSTR
# TC :
# SC :

def helper(self, mid, n, s, nums):
seen = set()
'''
for i in range(n-mid+1):
substr = s[i:i+mid]
hash_val = hash(substr)
if hash_val in seen:
return True
else:
seen.add(hash_val)
return False'''

h = 0

# starting hashing
for i in range(mid):
h = h*26 + nums[i]

seen.add(h)

for i in range(1, n-mid+1):
h = h * 26 - nums[i-1] * 26**mid + nums[i+mid-1] *26**0
if h in seen :
return True
return False


def longestRepeatingSubstring(self, s):
"""
:type s: str
:rtype: int
"""
n = len(s)

nums = [ord(ch) - ord('a') for ch in s]

left = 0
right = n-1

while left <= right:
mid = left + (right-left) // 2
if self.helper(mid, n, s, nums) == True:
left = mid + 1
else:
right = mid - 1

return left - 1


Not sure why this is not working for one of the test cases
Can someone help me out?

muktaparab
Автор

Great Explanation. Keep it up. Thank you

parasnath