You are not logged in. Please login at www.codechef.com to post your questions!

×

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

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

va1ts7_100's gravatar image

3★va1ts7_100
4721733
accept rate: 11%

closed 13 Sep '18, 00:48

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


Go through this link link text

link

answered 12 Sep '18, 19:35

lakh's gravatar image

4★lakh
1395
accept rate: 23%

Hey , I got my mistake , thanks for the reply :)

(13 Sep '18, 00:47) va1ts7_1003★

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • 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