left = 1
and right = N
(length of the string).left
is less than right
:
a. Calculate the middle point L = left + (right - left) / 2
.
b. Use the Rabin-Karp algorithm to check if there is a duplicate substring of length L
.
c. If a duplicate is found, set left = L + 1
to search for a longer substring.
d. If no duplicate is found, set right = L
to search for a shorter substring.left - 1
, or an empty string if no duplicate substring exists.