How To Solve Algorithms - Longest Common Prefix

Поделиться
HTML-код
  • Опубликовано: 4 ноя 2024

Комментарии • 107

  • @jordantalbot8584
    @jordantalbot8584 5 лет назад +16

    Thank you for the content man. Your channel is so underrated. This is my go to channel now. Keep it up man and your channel will blow up! Like everybody said use the playlist feature for similar content it makes a huge difference.

    • @WebDevSimplified
      @WebDevSimplified  5 лет назад

      Thanks! I have these algorithm videos already in a playlist and have many playlists for my similiar content on my channel.

  • @jeremyzhang8603
    @jeremyzhang8603 3 года назад +3

    This is the nicest explanation I have ever had! Please do more leetcode problems like this!

  • @Sonoioilmago
    @Sonoioilmago 5 лет назад +9

    Love this series! I'd love to see more of the thought process and what clues to look for in the challange description to structure the code. I'm a beginner and sometimes struggle with my weird thought processes! Thank you for the great vid!

    • @WebDevSimplified
      @WebDevSimplified  5 лет назад +2

      That is a great suggestion. I have another algorithm video coming out soon, so hopefully I explained it a bit more in depth for you.

  • @ROotHM
    @ROotHM 3 года назад +2

    These are amazing, and I'd love to see your breakdown of all the major sorting algorithms - along with a brief explanation of when it would be best to implement these types of sort

  • @JoeWong81
    @JoeWong81 5 лет назад +2

    Thanks a lot bro! love your no nonsense teaching style. Please do more leetcode walkthroughs in the future.

    • @WebDevSimplified
      @WebDevSimplified  5 лет назад +1

      I plan to keep covering them. They are fun to make.

  • @shuvajitmohanty9595
    @shuvajitmohanty9595 5 лет назад

    You have "simplified" this algo with ease....Thank you...Wish for these kind of videos on algo everyday

  • @pushpakgupta7396
    @pushpakgupta7396 5 лет назад

    please make a series of this and never stop....thanks for everything. God bless you

    • @WebDevSimplified
      @WebDevSimplified  5 лет назад

      I have a couple algorithm videos and plan to make more.

  • @f3-faithfitnessfinance
    @f3-faithfitnessfinance 4 года назад +1

    Man you should continue with this series ❤️
    You are awesome!!

  • @PortEXE
    @PortEXE 5 лет назад

    Great video! RUclips needs more of these algorithm videos.

  • @mandihaase2744
    @mandihaase2744 3 года назад

    I absolutely love this series!

  • @avagsargsyan404
    @avagsargsyan404 Год назад

    Thank you! Great solution!

  • @ActiveZeni
    @ActiveZeni 5 лет назад

    Have a series going through most of leetcode algo problems (easy/medium difficulties)! Great video!

  • @Lads-
    @Lads- 5 лет назад +1

    thank you so much! love this series please make more of algorithms series!

  • @miw879
    @miw879 3 года назад

    Thank you soo much for making this tutorial This helped me alot!! You are the best!!

  • @obasajujoshua9860
    @obasajujoshua9860 4 года назад +1

    This is great man, thank you so much for this.

  • @hikemalliday6007
    @hikemalliday6007 2 года назад

    well said and good audio quality

  • @KallyanBRoy
    @KallyanBRoy 4 года назад

    Dude, you are a true 'Algorithmist'🥰🥰

  • @shreyasd4663
    @shreyasd4663 5 лет назад

    Just subscribed! The more you will share algorithms video the 10x more I am gonna share your algorithm video links with internet!

    • @WebDevSimplified
      @WebDevSimplified  5 лет назад +1

      I'm really glad you enjoyed it.

    • @shreyasd4663
      @shreyasd4663 5 лет назад

      @@WebDevSimplified they only topic that doesn't put dust on internet is PROBLEM SOLVING. It's a win-win thing. You learn more you grow; you share it on RUclips channel grows! Do share and make it happen! ;)

  • @BrendanMetcalfe
    @BrendanMetcalfe 4 года назад

    Well done!

  • @crestmarinaris6113
    @crestmarinaris6113 5 лет назад

    Thank you for the video =) always look forward to these algorithm series.

  • @BrendanMetcalfe
    @BrendanMetcalfe 4 года назад

    Just subbed. Your channel is gold!

  • @yesweet
    @yesweet 5 лет назад

    I hope you could kindly show us how you create the video, all your technics help understanding while keeping all clean, very impressive, few can compete with you on this point. 👍

    • @WebDevSimplified
      @WebDevSimplified  5 лет назад

      Thank you. What do you mean by showing you how to create the video?

  • @nora8200
    @nora8200 4 года назад

    Thank you for this awesome video!

  • @manishbhatt1101
    @manishbhatt1101 5 лет назад

    Thank you Web Dev Simplified. This is good!

  • @justcodingandwhatnot9890
    @justcodingandwhatnot9890 2 года назад

    thank you this helped alot !!

  • @BrendanMetcalfe
    @BrendanMetcalfe 4 года назад +2

    A python implementation people may find helpful.
    class Solution:
    def longestCommonPrefix(self, strs: List[str]) -> str:
    longestPre = ""
    if strs:
    for i in range(len(strs[0])):
    char = strs[0][i]
    for j in range(len(strs)):
    try:
    if strs[j][i] != char:
    return longestPre
    except:
    return longestPre
    longestPre = longestPre + char
    return longestPre

  • @4541047
    @4541047 5 лет назад +1

    I love your channel man!
    You are a pro, and your explanations are the best.
    Can you please make a video on notifications in PWA?
    Thanks

    • @WebDevSimplified
      @WebDevSimplified  5 лет назад +1

      I plan to eventually jump into some PWA videos but I still have a lot of topics I want to cover first.

  • @MrWolfgangWeiss
    @MrWolfgangWeiss 5 лет назад

    Well done, great explanation!

  • @akamfoad
    @akamfoad 5 лет назад

    That was nice problem to solve and great explanation from you, I’ll skip the code and write it by mslf🤍

  • @vladimirjean
    @vladimirjean 5 лет назад

    Awesome tutorials like always!

  • @KhoaNguyen-mv2mu
    @KhoaNguyen-mv2mu 4 года назад

    beautiful amazing fantastic mind-cracking idea :))

  • @janezklun
    @janezklun 5 лет назад

    Great topic and nice solution, Thanks

  • @manikumarponnuru7271
    @manikumarponnuru7271 4 года назад

    I subscribed your channel after watching the first video. I would love to listen more of these algorithms from you. if possible can you make the video on Binary Search and Binary Tree?

  • @qwertykeypad789
    @qwertykeypad789 5 лет назад

    You are doing great!!!
    Please give as a full in-depth tutorial on MongoBD
    And use some live example to use it on project

    • @WebDevSimplified
      @WebDevSimplified  5 лет назад +1

      That is on my list of todos. I have a Node.js MongoDB course that is free on RUclips and covers Node.js and MongoDB in depth if you want to check that out.

  • @praniltunga
    @praniltunga 5 лет назад

    Nice content and covered in a very nice way 🙏👍 thanx man🙏

  • @tsukasa8179
    @tsukasa8179 2 года назад

    Legendary

  • @primordialmind
    @primordialmind 2 года назад +2

    There is a bug in the code actually. For example,
    strs = ["ab", "a"] will throw an index out of range error,
    We are comparing all indexes of strings with string 1, which in our case is "ab".
    Second string is of length 1. So, accessing the index 1 will produce an error.

    • @woto6090
      @woto6090 2 года назад

      Yes, that's why you should sort the list with key=len first. Now you won't run in to index errors because you have the shortest member of the array.

    • @primordialmind
      @primordialmind 2 года назад

      @@woto6090 Why add O(nlogn) overhead, when you can make it work by slight if/else checks?

  • @scenesofworld1066
    @scenesofworld1066 5 лет назад

    Also need php tutorials .great work

    • @WebDevSimplified
      @WebDevSimplified  5 лет назад

      I probably won't be doing much PHP on this channel since I do not enjoy it as much and it is much less popular.

  • @kousalyadevi5209
    @kousalyadevi5209 Год назад

    Make a video on Longest Common "Substring" for "more than two strings"

  • @krishy9661
    @krishy9661 5 лет назад +1

    Hi, Great explanation. Can you please make a video of how to solve Maximum sum sub array problem using Kadane's Algorithm in Javascript?

  • @vishalscit
    @vishalscit 5 лет назад +3

    Quick question.Shouldn't j loop start from 1 though ? Thanks for your videos dude.

    • @herrklaus
      @herrklaus 3 года назад

      Smart! Saves him the time of running it against the string he's already using as a reference.

  • @oop_web7707
    @oop_web7707 5 лет назад

    Thank you so much. This was very useful

  • @omerm80
    @omerm80 2 года назад

    Thank You! just subscribed to your channel:)

  • @samartajshaikh2601
    @samartajshaikh2601 4 года назад +1

    it would be better if you had also covered the divide-and-conquer approach and binary-search approach to solve this problem.

  • @chrisdanikas7918
    @chrisdanikas7918 5 лет назад

    Great video dude!

  • @ibeeliot
    @ibeeliot 4 года назад

    You're dope, brother.

  • @pawanvora
    @pawanvora 5 лет назад +2

    I am no JS expert, but I was wondering if the inner loop should start with j=1... since j = 0 would refer to the same string as the outer loop. Thanks.

    • @WebDevSimplified
      @WebDevSimplified  5 лет назад

      That is correct. Good catch!

    • @diegocastro7434
      @diegocastro7434 4 года назад

      I was thinking of this too but that would mess up the case if there was only one string. Great idea but you also would need to add if len(strs)==1 return strs[0]

  • @mareimorsy3182
    @mareimorsy3182 5 лет назад

    Thanks a lot .... Best explanation ever!!! :D

  • @parasarora5869
    @parasarora5869 5 лет назад

    great one!!!

  • @tannerbarcelos6880
    @tannerbarcelos6880 3 года назад

    Vertical method is very intuitive.

  • @michaelrooze278
    @michaelrooze278 2 года назад

    What if the first word is a million characters long though? Should we first sort the words by length, or would that be even worse space-time complexity?

  • @ikramikky2838
    @ikramikky2838 5 лет назад

    thank you very much

  • @dim_1074
    @dim_1074 2 года назад

    You could also use a trie.

  • @kumaresanperumal2581
    @kumaresanperumal2581 4 года назад

    Does this program use Big O notation?

  • @pushpakgupta7396
    @pushpakgupta7396 5 лет назад

    more algorithm videos pls

  • @luojihencha
    @luojihencha 4 года назад +1

    And binary search method man?

  • @vinamra4893
    @vinamra4893 5 лет назад

    There is a bug here. Suppose the String[] strs = [apple, ape, a]
    Starting with i = 0, 'a' is added to prefix.
    (BUG HERE) Then i = 1, here there will be an ARRAYOUTOFBOUND for
    i = 1 , j = 2 ...strs[j][i] for last string 'a'.

    • @WebDevSimplified
      @WebDevSimplified  5 лет назад +1

      Javascript does not have array out of bounds errors. It just returns undefined if there is nothing at that index of the array.

    • @vinamra4893
      @vinamra4893 5 лет назад +1

      Oh my bad! I used Java to program this and found it might give error.
      Thanks for reply and making this video! Otherwise I would have not understood concept of vertical scanning.

    • @WebDevSimplified
      @WebDevSimplified  5 лет назад

      @@vinamra4893 No worries. I am really glad you enjoyed the video.

  • @memeta100
    @memeta100 4 года назад

    Thx you got subscription by me

  • @Benescoli
    @Benescoli 4 года назад

    I can't do that, even you explain me, i guess that i have to really train in algorithmes

  • @ibeeliot
    @ibeeliot 4 года назад

    You have such a great demeanor. Keeeeeeep it up, bro. Maybe just get a light for your face, lol.

  • @AhSoh7091
    @AhSoh7091 5 лет назад

    what is the pregress of two for loop in nested. Is the frist loop fn only execute one time then going into second loop fn, after second loop is finished* condition finished then return back to first loop for second time of first loop fn then go second loop fn again? hope helper can understand what i want to said =)

  • @DanielLee-rr2qj
    @DanielLee-rr2qj 5 лет назад

    Anyone know the run time complexity of this solution? It's O(n^2) isn't it? I feel like there HAS to be a better way of doing this..

    • @WebDevSimplified
      @WebDevSimplified  5 лет назад +1

      If you go to the leetcode link in the description they have breakdowns of all the different solutions and time complexities. While this is not the fastest method it is significantly easier and not much slower.

    • @DanielLee-rr2qj
      @DanielLee-rr2qj 5 лет назад

      @@WebDevSimplified Ahh got it. Thank you!

  • @arunvijay2279
    @arunvijay2279 2 года назад

    ["ab", "a"] = above code will fail for this case

  • @usama2576
    @usama2576 2 года назад

    Your solution won't work for ["ab", "a"]

  • @snowsol
    @snowsol 3 года назад

    A *P P* L

  • @jankidepala
    @jankidepala 4 года назад +1

    hair is so distracting :P

  • @garrethhynes1201
    @garrethhynes1201 2 года назад

    This is working for me on Leetcode but when I copy it into VS code it returns 'undefined' when I pass in the array -
    const test = ["flower","flow","flight"]
    console.log(longestCommonPrefix(test))
    Has anyone got any idea why this might be?
    Thanks and great video!!

    • @primordialmind
      @primordialmind 2 года назад

      There is a bug in the code actually. For example,
      strs = ["flower", "flow", "flight"] will throw an index out of range error,
      We are comparing all indexes of strings with string 1, which in our case is "flower".
      Second string is of length 4. So, accessing the index 4 will produce an error.