×

# [closed] Calculate Longest common substring using hashing + binary search

 0 I was going through the editorial editorail When they try to calculate hash for a specefic segment in a string using the following logic Hash(S[l..r]) = (Hash(S[0..r]) - Hash(S[0..l-1]) * MAGIC^(r-l+1)) % MOD How this relation is working ?? what is the logic behind multiplication with MAGIC^(r-l+1) ?? As i observed , the logic should be , Hash(S[l..r]) = (Hash(S[0..r]) - (Hash(S[0..l-1]* MAGIC^(l)))%MOD +MOD) % MOD  Can someone plz explain the same ?? asked 12 Sep '18, 13:01 472●1●7●33 accept rate: 11%

### The question has been closed for the following reason "Question is answered" by va1ts7_100 13 Sep '18, 00:48

 1 Go through this link link text answered 12 Sep '18, 19:35 4★lakh 139●5 accept rate: 23% Hey , I got my mistake , thanks for the reply :) (13 Sep '18, 00:47)

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×1,056
×344
×38

question asked: 12 Sep '18, 13:01

question was seen: 135 times

last updated: 13 Sep '18, 00:48