Longest Duplicate Substring | TRIE | Rolling Hash | Binary Search | Leetcode

Sdílet
Vložit
  • čas přidán 18. 06. 2020
  • This video explains a very important programming interview problem which is to find the longest duplicate substring in the given string.There are many ways to solve this problem.I have explained 3 methods to solve this problem.The first method is by using dynamic programming because this problem is a variant of LCS or longest common substring.DP fails because we can't make a large table.The second approach is to solve it using TRIE.In this approach, we keep inserting all substrings of given size and whenever during insertion in our trie, we finnd that the substring is already present then that must be a common substring.We apply binary search on length of substring to find the maximum length for which there are two duplicate substrings.The third approach is by using rolling hash, binary search and hashmap.This is making use of rabin karp algorithm.This is the fastest among the 3 methods explained.The fastest method to solve this problem is by using Ukkonen's suffix tree, which solves this problem in two steps in just O(N) time.I have explained all the methods with intuition and proper examples.I have also shown the code walk through at the end of the video.
    CODE LINK is present below as usual. If you find any difficulty or have any query then do COMMENT below. PLEASE help our channel by SUBSCRIBING and LIKE our video if you found it helpful...CYA :)
    =================================================================
    INSTAGRAM: / surya.pratap.k
    LinkedIn: / surya-pratap-kahar-47b...
    =================================================================
    CODE LINK: gist.github.com/SuryaPratapK/...
    USEFUL LINKS:-
    Longest Common Substring (LCS): • Longest common substri...
    Basics of trie: • Basics of trie
    TRIE Insertion & Search: • Trie insertion and search
    TRIE Deletion & Search: • Trie deletion and search
    Rolling Hash (Rabin Karp algo): • Rolling hash | Rabin k...

Komentáře • 216

  • @hemayetchoudhury2411
    @hemayetchoudhury2411 Před 4 lety +15

    how does this channel not have more subs? some of the most detailed and simplified lc explanations here

  • @shantanumapari6679
    @shantanumapari6679 Před 4 lety +3

    Every morning I wake, I watch your video! YOu became my morning routine! Thank you so much

    • @techdose4u
      @techdose4u  Před 4 lety

      😂Hahahaa....Always nice to gather knowledge.

  • @heroicrhythms8302
    @heroicrhythms8302 Před 11 měsíci

    Thanks for the Series, I watched all the videos in this series!

  • @svcba_hvac
    @svcba_hvac Před 4 lety +6

    Great explanation, thank your, "The man , the myth , the legend" learned this and use it, :)

  • @saurabhsomani9188
    @saurabhsomani9188 Před 4 lety +1

    This is the Best LeetCode problem channel on CZcams by miles.

    • @techdose4u
      @techdose4u  Před 4 lety +1

      You declared me a leetcode 😅

  • @ibrahimshaikh3642
    @ibrahimshaikh3642 Před 4 lety +7

    This video has prerequisite, a lot to learn

  • @mananshah3471
    @mananshah3471 Před 4 lety +2

    This is brilliant, kudos to your dedication!

  • @Sathyaanarayanan
    @Sathyaanarayanan Před 4 lety +5

    This is too good... thank you. I hope the solution can be further improved if you calculate the hashes using two hash function in order to avoid rechecking the string when collision occurs . If the hashes of two string are same then compare the hashes which was calculated using other hash function. So the probability will be (1/m1 * 1/m2). I will try to solve and post the solution.

  • @MohitBhagwani94
    @MohitBhagwani94 Před 4 lety +6

    Hi Folks,
    Is there any reason behind to choose 10000007 number?
    Before posting this question I did a little bit of Googling and what I found about 10000007 is that 10000007 is used to avoid overflow and it's a first 8 digits prime number. And as mentioned in the video as well that he is taking the prime number as 10000007. But actually, 10000007 is not a prime number, 10000007 is divisible by 941.
    So what is the significance behind using 10000007 number? There are prime number bigger than 10000007 for example(10000019), why we are not using those numbers?
    I'm asking this question just out of curiosity, there is nothing wrong in your algorithm. Your code is working absolutely fine.
    Thanks in advance.

    • @MohitBhagwani94
      @MohitBhagwani94 Před 4 lety

      @@MinhNguyen-fs6qh Can you please post the link here.

    • @laxmandesai573
      @laxmandesai573 Před 3 lety +1

      The number to take is 1e9+7 (1000000007) not 1e8+7 (what you have mentioned). The number 1e9+7 is a really common modulo and is prime too Also since approx 10^9 (2^32) is limit for long int (or long in c++).

  • @bobsponge8544
    @bobsponge8544 Před 2 lety

    Best explanation so far for LDS problem..

  • @kaichenghu3826
    @kaichenghu3826 Před 4 lety +15

    The man , the myth , the legend!

    • @techdose4u
      @techdose4u  Před 4 lety +1

      What is this dialogue 😂

    • @abe10
      @abe10 Před 4 lety

      Scott Sterling!!

  • @AyushRaj-gf2ce
    @AyushRaj-gf2ce Před 3 lety

    thank you so much for detailed explanation!! :))))

  • @marianachamonbh
    @marianachamonbh Před 4 lety +2

    Very clean and direct explanation, thanks a lot!

  • @melwinalm
    @melwinalm Před 4 lety +1

    Wow. This is a great explanation. Thanks. Keep doing the good work.

  • @ankababuyou
    @ankababuyou Před 4 lety +1

    Thanks for posting. I would like to specially appreciate your effort to explain the DP approach and the down side of it for this problem ( given the constraints). Infact, I haven't yet gone thru full video.

    • @techdose4u
      @techdose4u  Před 4 lety +11

      Go through man. It took me 6 hours to create this after long day at office. I din't sleep the entire night working on this :(

    • @ankababuyou
      @ankababuyou Před 4 lety

      @@techdose4u I did go thru, thanks for wonderful explanation.

  • @AbhayKumarAgrawal
    @AbhayKumarAgrawal Před 4 lety +1

    Amazing, i wait for your video, No one explain better that you❤

  • @tianjieshen5372
    @tianjieshen5372 Před 4 lety +1

    Excellent video quality, detailed explanations and dedication!

  • @agileprogramming7463
    @agileprogramming7463 Před 4 lety +2

    Sir I have no words for how much I appreciate this

  • @ntt1903
    @ntt1903 Před 4 lety +1

    Thank you for your great video! What tools are you using to draw your explanation?

  • @aayushnevatia7
    @aayushnevatia7 Před 4 lety +1

    This video is much better than the video that you made on rabin karp ...So thankful to you

  • @aravinds6406
    @aravinds6406 Před 10 měsíci

    Well explained

  • @satyambhardwaj1688
    @satyambhardwaj1688 Před 4 lety +2

    Feels like i ve arrived at right place to master DS and Algo

  • @PriyankaSingh-pn8xv
    @PriyankaSingh-pn8xv Před 2 lety

    Nice explanation

  • @parthgupta3552
    @parthgupta3552 Před 4 lety +2

    GOAT 🙌
    Hats off to your dedication and explanation

  • @AARVINDHBEE
    @AARVINDHBEE Před 4 lety +25

    Its 4.30 am and I don't care .... I'm going to watch it.

    • @techdose4u
      @techdose4u  Před 4 lety +3

      😂 That's the spirit :)

    • @arpitsahu9940
      @arpitsahu9940 Před 4 lety +1

      It's 5:12am but even I'm gonna watch it !!
      Night Apes strong together xD

    • @techgamer1333
      @techgamer1333 Před 4 lety +3

      It's 8:04 and i don't care ,I'm gonna Watch it and Memorize Everything😎😎

    • @techdose4u
      @techdose4u  Před 4 lety +2

      😁

    • @techdose4u
      @techdose4u  Před 4 lety +2

      😂

  • @amangupta9776
    @amangupta9776 Před 4 lety +1

    good work .......your approach always helps to all the beginners.....

  • @MahirHasancse21
    @MahirHasancse21 Před 4 lety +1

    The Extraordinary
    Thank you very much for your video❤

  • @shresthmishra9329
    @shresthmishra9329 Před 4 lety +1

    Its 5:25 and i am gonna start my day with this video . : )

  • @shaheenrafiq5974
    @shaheenrafiq5974 Před 2 lety +6

    who all here from today's leetcode challenge XD

  • @vinaykumardahiya4260
    @vinaykumardahiya4260 Před 3 lety +1

    You deserve many more likes and subscribers!

  • @pranavgautam1958
    @pranavgautam1958 Před 4 lety +2

    puri video ek tarf last ka subscribe krne wala part ek taraf!

  • @vaishnavikulkarni8104
    @vaishnavikulkarni8104 Před 4 lety +1

    Sir you are an inspiration!

  • @awsomeoproductions4
    @awsomeoproductions4 Před 4 lety +1

    What software do you use for your sketches?

  • @yashmahant5017
    @yashmahant5017 Před 3 lety +1

    Loved it!

  • @AjayKumar-un2fz
    @AjayKumar-un2fz Před 4 lety +1

    Your explanation is really awesome...👏

  • @palakmantry
    @palakmantry Před 4 lety

    Can anyone please explain why dont we consider string of length 4 while doing binary search?

  • @AkshayKumar-xh2ob
    @AkshayKumar-xh2ob Před 2 lety

    Awesome video. Can you also tell how you came up with the solution, what ticked you in right direction?

  • @yaswanthchunduru5298
    @yaswanthchunduru5298 Před 3 lety +1

    Your videos are awesome

  • @cyruspassi457
    @cyruspassi457 Před 4 lety +4

    Your dedication👍👍👍

  • @atulyadav9448
    @atulyadav9448 Před 4 lety +1

    Nice explained!!! Keep it up!!

  • @shubhamlahoti9758
    @shubhamlahoti9758 Před 2 lety +2

    Thanks for the explanation. Unfortunately, your rolling hash solution gives TLE in one test case. I am unable to find a proper cpp solution for this problem to get ac :(

  • @ankitbhardwaj2574
    @ankitbhardwaj2574 Před 3 lety +1

    amazing concept!

  • @nileshlakra7375
    @nileshlakra7375 Před 4 lety +3

    You deserve million subscribers

  • @mayankjain876
    @mayankjain876 Před 4 lety +5

    Sir there is an space optimization approach in lcs can we solve with that approach
    In which we take only lcs[2][n+1]

    • @thunderbolt8632
      @thunderbolt8632 Před 4 lety +1

      I was also trying this way,but seriously messed up my code and left it😅

    • @thunderbolt8632
      @thunderbolt8632 Před 4 lety +1

      Btw,Did u try solving this way?

    • @naruto-qk8zr
      @naruto-qk8zr Před 3 lety

      This approach is O(n) time complexity
      Will give tle

  • @bhuvaneshsankar7839
    @bhuvaneshsankar7839 Před 4 lety +3

    Sir your explanations are awesome. Kindly put videos for leetcode biweekly contest and weekly contest too so that we can understand the problems which we were unable to solve during the contest.

    • @techdose4u
      @techdose4u  Před 4 lety +1

      I don't get time bro...otherwise I would. Maybe sometime in future I will try :)

    • @bhuvaneshsankar7839
      @bhuvaneshsankar7839 Před 4 lety +1

      @@techdose4u Okie bro. May be you can solve only the hard problem and post if you have time.

    • @techdose4u
      @techdose4u  Před 4 lety +2

      I was just talking about the hard one 😅 First 3 are generally simple. Hard ones takes a lot of effort to prepare and make video. 4th question preparation will take more time than first 3 combined 😅

  • @hymnish_you
    @hymnish_you Před 2 lety +1

    Dhanyawad Dada

  • @ismail8973
    @ismail8973 Před 3 lety +1

    Great vedio. I have a doubt why are you adding the prime number p in line no 18 in the code shown in vedio 28:34??

  • @Cmes315
    @Cmes315 Před 4 lety +2

    Great explanation, but I have a little bit confused that why do we need + p here?
    hash = ((hash-roll[size-1]*(s[j-size]-'a'))%p + p)%p;

    • @md_aaqil8027
      @md_aaqil8027 Před 4 lety

      Same Confusion for me also bro

    • @JaspreetSingh-gz2uh
      @JaspreetSingh-gz2uh Před 4 lety +3

      whenever we are subtracting two numbers and take module, the chances are result can be negative. negative hash value will give wrong answer. So to get assured +ve answer we add modulo to it and then take modulo.

  • @vishnuvardhan-md1ux
    @vishnuvardhan-md1ux Před 4 lety +1

    Excellent explanation.

  • @youssifgamal8545
    @youssifgamal8545 Před měsícem

    You can get rid of the logn of the map by using a hash map, and handle the collison by using pairs of integers with different mods and bases

  • @tanvirkekan6111
    @tanvirkekan6111 Před 2 lety

    nice video, but if we can add some details like why the ml = 3 it's important to understand what is the logic behind it.

  • @thunderbolt8632
    @thunderbolt8632 Před 4 lety +3

    Finally aa gyi video!Hats off to u sir

  • @ramkumar-so8xw
    @ramkumar-so8xw Před 4 lety +1

    Mass 🔥🔥🔥

  • @VikashKumar-ug5jx
    @VikashKumar-ug5jx Před 4 lety

    Thank you so much sir

  • @helpmeasap
    @helpmeasap Před 3 lety +1

    Why is the Time Complexity of the Rabin-Karp algorithm O(log(N) * N * log(N)), specifically why is the last factor log(N)? We're inserting into a hash with O(1) speed and need to check collisions with O(K) speed.
    Most sites say that the time complexity of Rabin-Karp is O(N + K) on average and O(NK) at worst. Shouldn't this mean that the total time complexity of binary search for substring length and Rabin-Karp combined is O(log(N) * (N + K)) on average and O(log(N) * N * K) at worst?

  • @jatinbhatoya8420
    @jatinbhatoya8420 Před 2 lety +1

    sir in the trie approach if on the very first iteration we didnt got any string which is already present then where do we move. beacuse we dont know what shuld be length of string. so sir can you please give me the code for trie+bs approach. pls sir.

    • @ishmam8643
      @ishmam8643 Před 2 lety

      I tried trie + bs approach, it's giving MLE. :(
      Let me know if u want the source code.

  • @reshovroy7799
    @reshovroy7799 Před 4 lety

    I have tried submitting your solution given on github on leetcode but it is giving TLE... could you please check?

  • @imranwahid9871
    @imranwahid9871 Před 3 lety +2

    Excellent explanation sir. Thanks a lot. But sir actually when I'm trying to implement the trie-based approach in LeetCode, it's showing memory limit exceeded for some larger inputs. Please help me with how to optimize the trie method. Thanks a lot, sir.

  • @siddharthsen4475
    @siddharthsen4475 Před 4 lety +1

    This approach was exactly what I thought yesterday, but I was not able to convert it into code...

  • @Karan-vq5vg
    @Karan-vq5vg Před 4 lety +1

    Can you please upload the video a bit early. BTW, the man, the myth, the legend!. Kudos to your consistency and dedication.

    • @techdose4u
      @techdose4u  Před 4 lety +5

      Office days are really hectic. On top of that if we get a hard problem to implement then it takes time. Yesterday I started at 10 PM and ended at 4:30 PM. Pain of making this video was tremendous. But I don't wanna rush. Quality of explanation is more important for me. Moreover, you can watch the video the next day morning as well.

    • @Karan-vq5vg
      @Karan-vq5vg Před 4 lety

      @@techdose4u Yeah, I get it. Such quality content is not available anywhere on the internet. Love your work and upload the video whenever you're comfortable. :)

  • @vibhu8281
    @vibhu8281 Před 4 lety +1

    Can we use same type of rolling hash which is used in Rabin-Karp algorithm?

  • @kaichenghu3826
    @kaichenghu3826 Před 4 lety +1

    Why is time complexity for rolling hash approach O(logn * n * logn)? I'm not sure how the second logn comes. You said in the video it's for map insertion and search. But isn't it O(n) in the worst case that we have to search through all start index in the list? Thanks

    • @techdose4u
      @techdose4u  Před 4 lety

      But that will be well distributed because of your hash function. We took a strong hash. It is extremely rare to collide when strings are different. If you wanna include that then exclude Map key search because logN is worst case. You can take LogN on avg for both collision and map key search. Sounds better?

    • @ameynaik2743
      @ameynaik2743 Před 2 lety

      @@techdose4u Still confused about second log n term. Do you have a video explaining this?

  • @harigovind11
    @harigovind11 Před 3 lety +1

    Thanks for the clear explanation. Can't we use java String classes hashcode method and store it in map instead of using custom hashcode logic ?

    • @techdose4u
      @techdose4u  Před 3 lety

      No idea on java :)

    • @harigovind11
      @harigovind11 Před 3 lety +1

      @@techdose4u Thanks for responding :) . After thinking a bit I realized the java String hascode function will scan all characters so the rolling hash has better time complexity.

    • @techdose4u
      @techdose4u  Před 3 lety

      @@harigovind11 great ❤️

  • @kushgupta6416
    @kushgupta6416 Před 4 lety +1

    Gajab

  • @meghamalviya8495
    @meghamalviya8495 Před 4 lety +1

    if we take % on each term as (1*26^2)%p + (2*26^1)%p + (3*26^0)%p , then also it will overflow?

    • @techdose4u
      @techdose4u  Před 4 lety +1

      No. But try to add two values and take mod again. Don't go on adding all values and then take mod. That will not give correct result.

    • @meghamalviya8495
      @meghamalviya8495 Před 4 lety

      @@techdose4u okay. Thank you!

  • @nikhilsangwan8324
    @nikhilsangwan8324 Před 4 lety +1

    instead of rolling hash can't we just slide the window and save in hash (unordered_map) and when it matches return the substring? code will be very short with same time complexity

    • @techdose4u
      @techdose4u  Před 4 lety +1

      This is very costly operation. We assumed logN for key search because key was INT. If you took key as string then if map is implemented using string as it is then time will go to NlogN just in map. Instead of rolling, you can simply take a roll varialble and subtract last hash weightage and add new hash. This is rolling hash by using 1 variable. But, debugging is easier taking utility array roll. That's why I took it.

    • @nikhilsangwan8324
      @nikhilsangwan8324 Před 4 lety

      @@techdose4u Thanks for the explanation. I really appreciate your work.

  • @vaibhavsharma226
    @vaibhavsharma226 Před 3 lety

    Can Alpha be an value instead of 10 and 26?

  • @viditvivo-account5878
    @viditvivo-account5878 Před 4 lety +1

    can we use sliding window approach here??

    • @techdose4u
      @techdose4u  Před 4 lety

      Rolling hash is sliding window technique.

  • @ashishchoksi8501
    @ashishchoksi8501 Před 4 lety +2

    i have doubt that last method you told we multiply for "ban => ( (26^2)+b + (26^1)+a + (26^0)+n )"
    but here you added in hash var above loop calculate hash => "ban => (26^0)+b + (26^1)+a + (26^2)+n )"
    why this is so??????????????????????

    • @ashishchoksi8501
      @ashishchoksi8501 Před 4 lety

      at 18:52 as your first hash value for "ban" is 1352 but in your code "ban" hash value is 689 why this happen?

    • @techdose4u
      @techdose4u  Před 4 lety +1

      We are sliding incrementing the the weightage. 1st time you have only B with weightage 2. Next time when you include A then B's weightage will increase by 1 digit. So hash will be multiplied by 26 (base value) and then add new char weightage 1 for A. Now once you calculate the entire window then you apply sliding window.

    • @sankarikarthick801
      @sankarikarthick801 Před 4 lety

      @@techdose4u This step is little confusing..It will be great if you could take an example and walk thru the code with the example

    • @dhanashreegodase4445
      @dhanashreegodase4445 Před 5 měsíci

      same question. did you get the ans?

    • @dhanashreegodase4445
      @dhanashreegodase4445 Před 5 měsíci

      did not understand this your first hash value for "ban" is 1352 but in your code "ban" hash value is 689 why this happen @@techdose4u

  • @otakulife3672
    @otakulife3672 Před 4 lety

    I used a set and applied binary search just like your second approach using a Trie, but I get TLE. Any ideas why this happens?
    I also early stop my my inner for loop, when there is a first match.
    Here is my code:
    class Solution:
    def longestDupSubstring(self, S: str) -> str:
    if not S or len(S) == 1:
    return ''

    d = set()
    left, right = 0, len(S)-1
    result = ''

    while left

  • @sumitsaha5520
    @sumitsaha5520 Před 4 lety +1

    I tried by trie data structure but stuck ..
    I've a doubt that if i check on mid = 4
    and I didn't get any Duplicate Substring of size = 4 then left = mid - 1 ???

    • @techdose4u
      @techdose4u  Před 4 lety

      No. Right = mid-1.

    • @sumitsaha5520
      @sumitsaha5520 Před 4 lety

      @@techdose4u yeh sorry right = mid - 1....but it's failed to some test cases :(

    • @moisascholar
      @moisascholar Před 4 lety +1

      Trie with Binary Search approach in C++ seems to fail TC 3...

  • @junxuchen2851
    @junxuchen2851 Před 3 lety +1

    I'm a little confusing... Why would we take the middle length instead of going through the whole String and build a very big Trie? Does it mean it's impossible to have a duplicate substring which length is longer than half the string?

    • @techdose4u
      @techdose4u  Před 3 lety +1

      I am doing binary search on length. 1st we will try by half length. If we find duplicate substring then we will increase our length like we do in binary search remember! So, there will be no problem. Did you understand?

    • @junxuchen2851
      @junxuchen2851 Před 3 lety

      @@techdose4u Thanks!!! This problem is way too hard...

  • @_ityadi
    @_ityadi Před 2 lety +1

    I got asked this question as Uber interview today. Sad that I could not crack it 😞😞 This seems too difficult to crack during 1 hr of interview

    • @techdose4u
      @techdose4u  Před 2 lety +1

      Don't worry. Keep learning for upcoming interviews 👍🏼

  • @sahukarinaveenkumar3188
    @sahukarinaveenkumar3188 Před 4 lety +1

    plz make a video on median of two sorted arrays

  • @aakashsharma2781
    @aakashsharma2781 Před 4 lety +1

    Bro,A small request can u please explain mockvita questions in cpp

    • @techdose4u
      @techdose4u  Před 4 lety

      Bro I am not getting time for it. Daily I am uploading something and I also go to office for 9 hrs.

  • @salahrekik4110
    @salahrekik4110 Před 4 lety

    Hello, thanks for the video.
    I have a question: I used Binary search for the length, then sliding window + a map where the key is a substring and the value is a list containing the beginning positions of this substring.This gave me TLE even though it has the same complexity as the algorithm with the Hash (I am jut using a string as Key instead of a Hash...)
    Can you help please? thanks :)
    Here's the code (Python):
    class Solution(object):
    def count(self, window, S):
    m1 = defaultdict(list)
    left = 0
    right = window
    sub = S[left:right]
    m1[sub].append(left)
    while (rightlen(maxStr)):
    answer = ans[0]
    maxStr = ans[1]
    left = mid+1
    return maxStr if answer!=-1 else ""

    • @minooshreddy2157
      @minooshreddy2157 Před 2 lety

      I have the same doubt . Do you know why its exceeding the time limit .

    • @vaibhavsingh4975
      @vaibhavsingh4975 Před 2 lety

      For comparison of keys in the map when we use a substring, the time taken is about O(n) . Whereas for comparing hash keys the time is constant.

  • @adarshsasidharan254
    @adarshsasidharan254 Před rokem

    holy crap

  • @tanmaybhatt6980
    @tanmaybhatt6980 Před 4 lety +3

    Take dose..!! Haha

    • @techdose4u
      @techdose4u  Před 4 lety +1

      Not able to pronounce is correctly even though I know the correct pronunciation 😂 I hope trollers will spare me 😂😂

    • @tanmaybhatt6980
      @tanmaybhatt6980 Před 4 lety

      You’re very kind my friend. You’re videos make hard problems easy. No more trolling. People love to ‘Take dose of Tech dose’.

  • @aswathsrimarir2501
    @aswathsrimarir2501 Před 4 lety +1

    Sir your actual code exceeds the time limit. What might be the issue??

    • @techdose4u
      @techdose4u  Před 4 lety +1

      2 reasons:-
      1. Maybe new test cases require more optimization
      OR
      2. New test cases might be covering extra boundary cases so that the code falls in infinite loop.
      Please take the latest code from leetcode discussions and try to compare or try with that. That will be helpful.

    • @aswathsrimarir2501
      @aswathsrimarir2501 Před 4 lety

      @@techdose4u ok sure. I will go through the discussions.

  • @raushankumar8897
    @raushankumar8897 Před 2 lety

    slide window me hash kaise nikal rhe....nhi smjha :( koi smjhayega kya

  • @gauravkhurana420
    @gauravkhurana420 Před 4 lety +1

    bhaiya suffix trie valla bhi smjha do...us trick se bhi bht questions solve hotte hai..
    pura youtube me kisi ne kraya bhi nhi hai suffix trie

    • @techdose4u
      @techdose4u  Před 4 lety

      Bro I din't get time. Already yesterday I din't sleep. Ukkonen suffix tree will be explained later when I finish covering all the basics.

    • @gauravkhurana420
      @gauravkhurana420 Před 4 lety

      @@techdose4u koi nhi bhaiya .... Aapka content vaise bhi bht tagda hota hai....

  • @samarthgupta7845
    @samarthgupta7845 Před 3 lety +1

    LCS can be done in 0(n) space

  • @spetsnaz_2
    @spetsnaz_2 Před 4 lety +1

    5:08 can we do it on our local machine?
    Will it work?? 😅

    • @techdose4u
      @techdose4u  Před 4 lety +1

      No. First thing is, you want to know how much memory your OS allocates for your compiler. You can't go beyond that even though you have more memory. If somehow you manage then you need more than 40GB ram. If you take care of these steps then it might take very long to run 10^10 computations. So, it's not feasible.

    • @spetsnaz_2
      @spetsnaz_2 Před 4 lety

      @@techdose4u 40GB RAM is my dream 😂😂

    • @spetsnaz_2
      @spetsnaz_2 Před 4 lety

      @@techdose4u Understood 🙏🏼
      So I need a, supercomputer to run this algorithm 😂

  • @prashanthchinthilla3968

    ((hash-roll[size-1]*(s[j-size]-'a'))%p + p)%p;
    Can someone explain why we are adding +p in the above code.

  • @streambai1045
    @streambai1045 Před 4 lety +1

    Could anyone tell why use number 10000007 ?

    • @techdose4u
      @techdose4u  Před 4 lety

      Use 1e9+7. I took it unknowingly that 1e7+7 is not a prime. It is divisible by 2 numbers. But it won't create any problem. Read Universal Hashing.

    • @streambai1045
      @streambai1045 Před 4 lety +1

      @@techdose4u Thanks for reply!

  • @piyushnaithani7689
    @piyushnaithani7689 Před 4 lety +1

    Could you provide your codeforces Id

    • @techdose4u
      @techdose4u  Před 4 lety

      No Id on CP platform as I never did CP.

  • @rishabhsinha3713
    @rishabhsinha3713 Před 4 lety

    Just for the record it is actually way more difficult to walk on a cake. Just saying. xD

  • @KhangNguyen-py9zr
    @KhangNguyen-py9zr Před 4 lety +1

    How do you get so smart?

    • @techdose4u
      @techdose4u  Před 4 lety

      Just keep coding daily. Those who practice more gets better. See William lin and Errichto. I am nowhere compared to them but I am trying to reach there someday. So, I code daily to take a step forward.

  • @shishpalvishnoi7974
    @shishpalvishnoi7974 Před 4 lety +1

    please provide code for trie solution.

    • @techdose4u
      @techdose4u  Před 4 lety

      Please that in discussions section. It's present there.

    • @shishpalvishnoi7974
      @shishpalvishnoi7974 Před 4 lety

      @@techdose4u it's by using rolling hash concept.

  • @hoyinli7462
    @hoyinli7462 Před 2 lety +1

    leave a cm before watching!

  • @hritiksharma7154
    @hritiksharma7154 Před 4 lety

    Can u help me with this problem by making video or sending code,
    Lazy Student
    Problem Description
    There is a test of Algorithms. Teacher provides a question bank consisting of N questions and guarantees all the questions in the test will be from this question bank. Due to lack of time and his laziness, Codu could only practice M questions. There are T questions in a question paper selected randomly. Passing criteria is solving at least 1 of the T problems. Codu can't solve the question he didn't practice. What is the probability that Codu will pass the test?
    Constraints
    0 < T

  • @AmandeepSingh-uq3wp
    @AmandeepSingh-uq3wp Před rokem

    Understanding rolling hash algorithm in this question is very difficult 😕

  • @akshatjain6854
    @akshatjain6854 Před 4 lety +1

    Bhai why we are taking window of size 3, there can be duplicate substring of size 4 or more as well.Please clarify

    • @techdose4u
      @techdose4u  Před 4 lety

      I already showed in the video that low=1 high=6 and mid=3. So we will search for 3. If found then we will update low and mid and search for higher values. Please rewatch.

    • @akshatjain6854
      @akshatjain6854 Před 4 lety

      @@techdose4u Ok thanks bro great tutorial

  • @shouvikdutta2825
    @shouvikdutta2825 Před 3 lety

    still tle 60/66 passed in python.

  • @soumya7430
    @soumya7430 Před 2 lety

    why not store the string in map rather than hash of string

    • @ismail8973
      @ismail8973 Před 2 lety

      storing string for each window takes more time, for each window we need time proportional to the length of string. By rolling hash this step is done in O(1) time.

  • @utkarshdevgan6199
    @utkarshdevgan6199 Před 3 lety

    Why are you searching smaller substrings when you have found one match because any search after that would have less length than the last successful search???

  • @Hav0c1000
    @Hav0c1000 Před 4 lety

    You totally skipped the time/space inefficient brute force:
    seen = set()
    longest = ""
    for i in range(len(S)):
    for j in range(i+1,len(S)+1):
    w = S[i:j]
    if w in seen:
    longest = w if len(w) > len(longest) else longest
    else:
    seen.add(w)

    return longest

  • @anitasrivastava983
    @anitasrivastava983 Před 4 lety +2

    The man , the myth , the legend!

    • @techdose4u
      @techdose4u  Před 4 lety +1

      Is it a famous dialogue I have never heard 😂

    • @anitasrivastava983
      @anitasrivastava983 Před 4 lety +2

      When someone does some kind of extraordinary work then we use this phrase :)

    • @techdose4u
      @techdose4u  Před 4 lety

      😅 Got it.