<p>Given a string <code>s</code>, consider all <em>duplicated substrings</em>: (contiguous) substrings of s that occur 2 or more times.&nbsp;The occurrences&nbsp;may overlap.</p>

<p>Return <strong>any</strong> duplicated&nbsp;substring that has the longest possible length.&nbsp;If <code>s</code> does not have a duplicated substring, the answer is <code>&quot;&quot;</code>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre><strong>Input:</strong> s = "banana"
<strong>Output:</strong> "ana"
</pre><p><strong class="example">Example 2:</strong></p>
<pre><strong>Input:</strong> s = "abcd"
<strong>Output:</strong> ""
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>2 &lt;= s.length &lt;= 3 * 10<sup>4</sup></code></li>
	<li><code>s</code> consists of lowercase English letters.</li>
</ul>

def RollingHash(s:str,currLen:int) -> str:
    if currLen==0 or currLen==len(s):return ""
    sp,ep,currHash, mod = int(0), int(currLen-1), 0, 1e9+7
    mp = {} # map that will hold the hash values and their corresponding indexes
    prime = 31 # you can try with 281 also
    currPrime = 1
    i = int(ep)
    while i>=0:
        currHash = (currHash + ((ord(s[i])-ord('a'))*currPrime)%mod)%mod
        if i!=0:currPrime = (currPrime * prime)%mod
        i -= 1
    mp[currHash] = []
    mp[currHash].append(0)
    while ep<=len(s)-2:
        nextHash = (prime*(currHash - (((ord(s[sp])-ord('a'))*currPrime)%mod)))%mod
        nextHash = (nextHash + (ord(s[ep+1])-ord('a')))%mod
        sp += 1
        ep += 1

        #check if nextHash value is already present in map or nor.If present then push curr sp in the existance list
        if nextHash not in mp.keys():
            mp[nextHash] = []
        else:
            for ind in mp[nextHash]:
                p1 = sp
                p2 = ind
                status = True
                while p1<=ep and p2<ind+currLen:
                    if s[p1] != s[p2]:
                        status = False
                        break
                    p1 += 1
                    p2 += 1
                if status:
                    return s[sp:ep+1]
        mp[nextHash].append(sp)
        currHash = nextHash
    return ""
class Solution:
    def longestDupSubstring(self, s: str) -> str:
        ans = ""
        low,high = 0,len(s)
        while(low<=high):
            mid = (low+high)//2
            curr = RollingHash(s,mid)
            if curr != "":# if reperation is get then search for right side
                low = mid+1
                ans = curr
            else:high = mid-1
        return ans
24500