Lecture 80: Longest Common Prefix Problem || Tries || C++ Placement Series

แชร์
ฝัง
  • เผยแพร่เมื่อ 23 ม.ค. 2025

ความคิดเห็น • 188

  • @md.ualiurrahmanrahat2400
    @md.ualiurrahmanrahat2400 2 ปีที่แล้ว +77

    finished your 60th video today. Came here to show my support. Please don't be disappointed as the view are declining. Once we finished the other videos, we will come here too. This is the only comprehensive DSA PlayList available on TH-cam. This is much much better than hundreds of paid courses.

  • @vaidanshkukreja8970
    @vaidanshkukreja8970 2 ปีที่แล้ว +155

    Is it just me or with everyone that feels babbar bhaiya is exhausted but still recording the video
    Bhaiya please take proper rest and then start the course again.
    We need your full power !!!

  • @Code0x64
    @Code0x64 ปีที่แล้ว +7

    Really Enjoyed this. However, one small check to be done for corner testcases:
    //insert all strings into Trie
    for (int i = 0; i < strs.size(); i++)
    {
    if(strs[i].empty()) // missing check to return in cases where the string is empty
    return "";
    t->insertWord(strs[i]);
    }

  • @human75788
    @human75788 2 ปีที่แล้ว +33

    ❤💯 already solved trie construction in the morning today of leetcode both recursive and iterative approaches, both were right just by understanding the logic from you... so simple and easily understandable

  • @inspiringzone12
    @inspiringzone12 2 ปีที่แล้ว +7

    Attandance ++
    Consistency++
    Thank you ++

  • @gb9374
    @gb9374 2 ปีที่แล้ว +14

    bhaiya big fan
    1 more approach :-
    sorting karke first and last string compare karenge to ans mil jayega
    string longestCommonPrefix(vector &arr, int n)
    {
    // Write your code here
    if(n==0)return "";
    if(n==1)return arr[0];
    sort(arr.begin(),arr.end());
    string ans="";
    string a=arr[0];
    string b=arr[n-1];
    for(int i=0;i

  • @aaryannaugaraiya1118
    @aaryannaugaraiya1118 2 ปีที่แล้ว +5

    Bhaiya, maza aarha h... Coding ab ho rhi h.. Leetcode ke questions bn rhe h..
    Happy😁
    Credit goes to you ☺

  • @do_not_want_to_show
    @do_not_want_to_show 2 ปีที่แล้ว +3

    Bhai saab, JOB + Consistency == Faadu 🔥🔥🔥.

  • @MohammadAmmar-jr3sp
    @MohammadAmmar-jr3sp 4 หลายเดือนก่อน +1

    We can clearly see how much effort you are putting to provide us the quality content.
    recording the video half asleep🙂🙂🙂 dedication level is ++
    GURU JI ++

  • @mr.himanshu4299
    @mr.himanshu4299 2 ปีที่แล้ว +2

    consistency vaps le aae ho bht ache bht ache

  • @akashkumarmaurya2319
    @akashkumarmaurya2319 2 ปีที่แล้ว +2

    maja aa rha hai .. previous day maine leet code , visual code , gfg se trise k question kara ,easy and loving this lecture for me...tq bhaiya for this...

  • @krishnaradhey2814
    @krishnaradhey2814 2 ปีที่แล้ว +4

    JAI SIYA RAM BHAI you are doing tremendous work

  • @varshadagar2140
    @varshadagar2140 2 ปีที่แล้ว +5

    loving it
    consistency++++++++

  • @NinjaCoders
    @NinjaCoders 2 ปีที่แล้ว +1

    Your teaching is really Excellent,
    very simple to understand

  • @prashantbirajdar9271
    @prashantbirajdar9271 2 ปีที่แล้ว +5

    wahh sirr another an exciting session ...wow.....but the second Trie mehtod approach giving TLE at submission time.... but first approach is optimal code solution for this problem...thanks sirrr...consistancy , respect , hardwork , dedication , passion ++++++

  • @Khushee117
    @Khushee117 2 ปีที่แล้ว +4

    I am in recursion .... we all are with you

  • @RavindraSingh-zg9eq
    @RavindraSingh-zg9eq ปีที่แล้ว

    no one can beat u bhai in teaching and knowledge

  • @utkarshsingh1457
    @utkarshsingh1457 2 ปีที่แล้ว +4

    Enjoyed a lot... Thanks for making such a quality content ❤️❤️

  • @excelexpertclasses6776
    @excelexpertclasses6776 ปีที่แล้ว

    completed this lecture babbar ji still continuing to complete your whole data structure series !!!!!

  • @fazerugbrug439
    @fazerugbrug439 2 ปีที่แล้ว +2

    aaag laga diya bhaiyaa

  • @ravivishvas3676
    @ravivishvas3676 2 ปีที่แล้ว +2

    next level efforts
    🔥🔥

  • @RajKumar-vq1nm
    @RajKumar-vq1nm 2 ปีที่แล้ว +2

    Back to form..U have given enough upcoming students..❤️

  • @AnonymousCoder7
    @AnonymousCoder7 2 ปีที่แล้ว +6

    Just watched video review of your course by @desi coder . My comment there is "Best DSA course on YT🏅🏅🏅"
    Really Love bhai .. Thanks a lot for putting such an efforts... Don't worry about People getting impatient about the completion of this course. I know this will be completed.
    Iss level ka content wo b free me ... Hatts offff... Traits of an Army attitude🏅🏅🏅
    Love,
    Abhishek Sharma
    Punjab

    • @bhawargujral3574
      @bhawargujral3574 2 ปีที่แล้ว

      I am from punjab as well..
      Which district by the way?

    • @AnonymousCoder7
      @AnonymousCoder7 2 ปีที่แล้ว +2

      @@bhawargujral3574 Hoshiarpur bro ... 🤝

  • @vishalgarna4580
    @vishalgarna4580 ปีที่แล้ว +1

    Osm content ❤❤❤😊😊

  • @Bad_Avadh
    @Bad_Avadh 2 ปีที่แล้ว +1

    int n=strs.size();
    string ans="";

    sort(strs.begin(),strs.end());

    string s1=strs[0];
    string s2=strs[n-1];

    for(int i=0;i

  • @shrutijaiswal871
    @shrutijaiswal871 2 ปีที่แล้ว +1

    Jaldi complete krrao bhaiya , mid March ka promise kiya tha apne , abb toh mid Aprila aaagya !!

  • @lokendrasingh9780
    @lokendrasingh9780 2 ปีที่แล้ว +1

    This series is helping alot❤❤👍👍😊😊

  • @amishapandey6875
    @amishapandey6875 ปีที่แล้ว +2

    Completed 80lectures!! 60 more to go!

  • @bhawargujral3574
    @bhawargujral3574 2 ปีที่แล้ว +2

    Consistency 😍 thank you for the course👏

  • @alokranjan3185
    @alokranjan3185 2 ปีที่แล้ว +3

    Thanks for this awesome series sir

  • @govindnair3135
    @govindnair3135 2 ปีที่แล้ว

    Love you bhaiyya ❤️😘....thanks a lot for this.....please don't change bhaiyya.....love youuuuu

  • @vashishthsharma4411
    @vashishthsharma4411 2 ปีที่แล้ว +1

    thank you bhaiya 😇😇🙏

  • @RohitKumar-oo8lo
    @RohitKumar-oo8lo 2 ปีที่แล้ว +1

    Bhaiya lage raho..hum thoda video peeche hai...aap please Videos banate jao..hum saath me hai aapke ! 🔥

  • @BhaiRayyanKiDuniya
    @BhaiRayyanKiDuniya 2 ปีที่แล้ว

    kk luv u bro good job MAKE Your FAMILY HAPPY AND SATISFIED WITH WHAT YOU DO

  • @RavinderSingh-yo7dx
    @RavinderSingh-yo7dx 2 ปีที่แล้ว +2

    I am really really impressed with the way you teach. Thanks much. I have a question and I hope you wont mind revealing it. Actually I am really very curious to know that how long or how much time do you study in a day?

  • @memorybyshubhammanitripath4368
    @memorybyshubhammanitripath4368 2 ปีที่แล้ว

    Maja aa gya bhaiya 😍😍😍
    Finally aap ko catch kar liya course pe
    Ab aap ke sath daily daily wale video dekhi ga
    Aur ab hoga practice starting se
    #reached
    Lekin bhaiya code link update kar do 😁
    Maja bahut aa raha
    Mera final sem chal raha lekin phir bhi continuous hu aap ke karan
    Kal mera paper hai 😂🤣😁🤣
    You are best 😍😍😍

  • @kumarpawansahh
    @kumarpawansahh 2 ปีที่แล้ว

    Krenge bhaiya ....aap ho toh mumkin hai

  • @yashasvic2429
    @yashasvic2429 2 ปีที่แล้ว

    Thanks Bhai, these tutorials really helped me all these times.

  • @rachit_joshi
    @rachit_joshi 7 หลายเดือนก่อน

    Thank You So Much BHRATA SHREE !!!!!!!

  • @vipulchaudhary_js
    @vipulchaudhary_js 2 ปีที่แล้ว +2

    Code here : leetcode.com/problems/longest-common-prefix/discuss/2659408/cpp-trie-love-babbar-approach

  • @gitanjalikumari9262
    @gitanjalikumari9262 2 ปีที่แล้ว

    great explanation...thank you so much for making our path easy

  • @Abhishek-ji6qj
    @Abhishek-ji6qj 2 ปีที่แล้ว

    #Python:-
    x = ["flower", "flosing", "flowing"]
    prefix = ""
    for i in range(len(x[0])):
    flag = 0
    temp = x[0][i]
    for j in range(1, len(x)):
    if not x[j][i] == temp:
    flag = 0
    break
    else:
    flag = 1
    if flag ==1:
    prefix+=temp
    else:
    pass
    print(prefix)

  • @BornHubisLive
    @BornHubisLive 2 ปีที่แล้ว +1

    Thanks A lot BHaiya.......RESPECT++;

  • @sumitrawat9526
    @sumitrawat9526 2 ปีที่แล้ว

    Bhaiya we are with you..

  • @codingindisguise
    @codingindisguise ปีที่แล้ว

    Easy and Smooth!!💯

  • @focus.placement5589
    @focus.placement5589 2 ปีที่แล้ว

    thanks bhaiya crystal clear hai

  • @laksheybanga8106
    @laksheybanga8106 2 ปีที่แล้ว

    Bhaiyaaa tussi great ho 💓💓

  • @arpitrajput6424
    @arpitrajput6424 2 ปีที่แล้ว +3

    Having problem to solve more problem anyone suggest me where i can ask my doubt ,any whatsapp group or discard server

  • @ashish4k07
    @ashish4k07 ปีที่แล้ว

    Is there any more optimzation in this like some people have used sorting

  • @jaydwarkadhish959
    @jaydwarkadhish959 2 ปีที่แล้ว +1

    Sir amazing video

  • @ajvlogs1501
    @ajvlogs1501 2 ปีที่แล้ว +6

    can someone please tell me how much syllabus of DSA is reamining and approximately how much videos will it take to complete,BTW execellent work bhaiya we can see all your efforts❤

    • @someshsangwan5302
      @someshsangwan5302 2 ปีที่แล้ว

      Dont worry bro i think there will be little topics like - DP and graph mostly

  • @AnkitRaj-pp6ph
    @AnkitRaj-pp6ph 2 ปีที่แล้ว +2

    Will this course continue

  • @TechUprise-by-Jyoti
    @TechUprise-by-Jyoti 2 ปีที่แล้ว

    Thank you bhaiya😄consistency OP🥰

    • @user-ic7mg6lz2k
      @user-ic7mg6lz2k 2 ปีที่แล้ว

      congratulations you have been selected amongst our shortlisted winners ✅
      A direct message 👆

  • @kunaljain1168
    @kunaljain1168 2 ปีที่แล้ว +2

    Make playlist for and Trie.

  • @heybiplabb
    @heybiplabb 2 ปีที่แล้ว +1

    Present bhaiya ✋

    • @user-ic7mg6lz2k
      @user-ic7mg6lz2k 2 ปีที่แล้ว

      congratulations you have been selected amongst our shortlisted winners ✅
      A direct message 👆

  • @KratosProton
    @KratosProton 2 ปีที่แล้ว

    Great explaination

  • @ArpitKumar-yo6up
    @ArpitKumar-yo6up 2 ปีที่แล้ว

    Thanku for making great videos bhaiya

  • @sukhjitsingh959
    @sukhjitsingh959 2 ปีที่แล้ว +1

    I trust you Babar thanks 👍

  • @shivkumar-og4ow
    @shivkumar-og4ow 2 ปีที่แล้ว

    Thanks alot bhaiya.. consistency++

  • @iteself_me
    @iteself_me ปีที่แล้ว

    160 ✅completed 👍Liked 2:30

  • @ayushgoyal8972
    @ayushgoyal8972 ปีที่แล้ว

    we can use linked list as well

  • @jessicasinha9009
    @jessicasinha9009 2 ปีที่แล้ว

    Thank u bhaiya for your efforts

  • @kshitizmayank7208
    @kshitizmayank7208 ปีที่แล้ว

    hello bhaiya ik this is too late to ask but looks like you were unwell/sick while recording this lecture ,is it true?
    thanks for the efforts you put for us

  • @nikhithreddy8543
    @nikhithreddy8543 2 ปีที่แล้ว

    Bhayya code submit karne ka samai time limit exceeded error aah raha hai. usko solve kaise kar raha tha??

  • @BetterCallHardik
    @BetterCallHardik ปีที่แล้ว

    is terminal helps edge cases like CODECHEF CODE we need as as 4 and not 7

  • @shantanu8880
    @shantanu8880 ปีที่แล้ว

    My logic was: We can insert one string to the trie, then for rest of the strings we need to check the common prefix, but here must be a catch, [coding, code, codingninjas] -> here ans should be cod, so we need to store the min(ans, tempStr).

  • @smanivesh
    @smanivesh 2 ปีที่แล้ว +1

    bhaiya.. what will be the Longest Common Prefix for ["flowering" , "flringow" , "flringight"]
    ans..fl or ring?? please resolve this confusion!!

    • @GrindMachine89
      @GrindMachine89 2 ปีที่แล้ว

      it should be ring , as it is "longest common"

    • @hiddenmaster1724
      @hiddenmaster1724 2 ปีที่แล้ว +1

      The correct ans is fl
      Reason is- question is about the longest common prefix and not longest common substring

    • @GrindMachine89
      @GrindMachine89 2 ปีที่แล้ว

      @@hiddenmaster1724 why ring is not prefix ?

    • @hiddenmaster1724
      @hiddenmaster1724 2 ปีที่แล้ว

      @@GrindMachine89 Prefix occurs at the beginning of root and not in between. "Ring" is a sub-part/sub-string.

    • @GrindMachine89
      @GrindMachine89 2 ปีที่แล้ว

      @@hiddenmaster1724 flringow and flringight has ring in first part only

  • @sukhpreetsingh5200
    @sukhpreetsingh5200 2 ปีที่แล้ว +1

    are mjja aa gya

  • @avishkarpatil5871
    @avishkarpatil5871 10 หลายเดือนก่อน

    9:09 // - Missing Case
    Make sure that -> i >= arr[j].size() not i > arr[j].size()
    if(i >= arr[j].size() || arr[j][i] != arr[0][i]){
    check = false;
    break;
    }
    // Complete Code
    string longestCommonPrefix(vector &arr, int n)
    {

    int m = arr[0].size();
    string ans = "";
    for(int i = 0; i < m; i++){
    bool check = true;
    for(int j = 1; j < n; j++){
    if(i >= arr[j].size() || arr[j][i] != arr[0][i]){
    check = false;
    break;
    }
    }
    if(check) ans.push_back(arr[0][i]);
    else break;
    }
    return ans;
    }

  • @nishudwivedi3478
    @nishudwivedi3478 2 ปีที่แล้ว

    Bhaiya os ki trh dbms Or cn ka series bhi start kariye please bhaiya humble request... 🙏🙏🙏

  • @jericodcosta2049
    @jericodcosta2049 2 ปีที่แล้ว +1

    Attandance marked now solving stack questions Josh is high

  • @nishudwivedi3478
    @nishudwivedi3478 2 ปีที่แล้ว +1

    Dsa course kb complete hoga...?

  • @deepakgarg2547
    @deepakgarg2547 2 ปีที่แล้ว +1

    Pls tell@Love babbar total kitni video aaygi DSA course mein pls ek idea bta do🙏🙏🙏🙏🙏🙏

  • @teenageworrior1634
    @teenageworrior1634 2 ปีที่แล้ว +1

    💯🙏Bhaiya lecture 17,18,19 .. etc ke handwritten notes bhi daliye plz🙏❤

  • @mihirvargante66
    @mihirvargante66 2 ปีที่แล้ว +2

    thanx:)

  • @SahilKasekar-h5w
    @SahilKasekar-h5w ปีที่แล้ว

    Hello Love Babbar sir, Thank you for sharing great knowledge. In this lecture you taught us one brute force solution with O(n*m) time complexity, I found one exception for shared solution, That code is not compatible with test case = [ "ab" , "a" ]. And I found quite better solution for that, which allows almost all test cases. If you allow me I want to contribute that updated code. Thank you.

  • @sukhjitsingh959
    @sukhjitsingh959 2 ปีที่แล้ว +1

    Can I get loan zero interest to buy new laptop ...need it badly now ....

  • @satyanarayanareddy8817
    @satyanarayanareddy8817 2 ปีที่แล้ว +1

    hi sir i am from andrapradesh (AP)i dont know hindi well i am seeing your videos using subtitles but from past videos onwards subtitles are turned off..can you please turn on for nextvideo on wards

  • @005lemdshahbazkhan2
    @005lemdshahbazkhan2 2 ปีที่แล้ว

    Are bhaiya kya hua live course ka, kuch toh update dedo usk bare mein

  • @akankshapandey8316
    @akankshapandey8316 2 ปีที่แล้ว

    Thanku Sir🙏

  • @studywithme66
    @studywithme66 2 ปีที่แล้ว

    Thanks for your affort

  • @divanshuprajapat6735
    @divanshuprajapat6735 2 ปีที่แล้ว

    bhaiya next video kab tak aaayegi?

  • @BhaiRayyanKiDuniya
    @BhaiRayyanKiDuniya 2 ปีที่แล้ว

    Hope to greet you someday after getting placed

  • @nishankdeep3084
    @nishankdeep3084 2 ปีที่แล้ว

    thank you bhaiya

  • @lapade
    @lapade ปีที่แล้ว

    Hanji 🎉

  • @NikhilSharma-qc1ez
    @NikhilSharma-qc1ez 2 ปีที่แล้ว +1

    Bhaiya lecture 81 kab ayega

  • @shresthkaushik6636
    @shresthkaushik6636 ปีที่แล้ว

    thx sir 🙏

  • @rakeshkrishali4020
    @rakeshkrishali4020 2 ปีที่แล้ว

    why its not working in leetcode

  • @divyadixit5607
    @divyadixit5607 2 ปีที่แล้ว

    If one of the input string is empty then it gives wrong answer

  • @prashantshukla6870
    @prashantshukla6870 2 ปีที่แล้ว

    Mza aagya bhaiaya

    • @user-ic7mg6lz2k
      @user-ic7mg6lz2k 2 ปีที่แล้ว

      congratulations you have been selected amongst our shortlisted winners ✅
      A direct message 👆

  • @063himanshumishra4
    @063himanshumishra4 2 ปีที่แล้ว

    Bhaiya moj kr diii

  • @BhaiRayyanKiDuniya
    @BhaiRayyanKiDuniya 2 ปีที่แล้ว

    keep it up

  • @jayant-baid
    @jayant-baid 2 ปีที่แล้ว +1

    Bhaiya iss video me timestamps dalna bhul gye

  • @muhammadsuleman8936
    @muhammadsuleman8936 ปีที่แล้ว

    Lecture was amazing sir!

  • @sajaljain712
    @sajaljain712 6 หลายเดือนก่อน

    LEET CODE 14: LONGEST COMMON PREFIX (SOLUTION CODE)
    class TrieNode {
    public:
    char data;
    TrieNode* children[26];
    bool isTerminal;
    int childCount;
    TrieNode(char ch){
    data = ch;
    for(int i=0;iisTerminal = true;
    return;
    }
    int index = word[0] - 'a';
    TrieNode* child;
    if(root->children[index] != NULL){
    child = root->children[index];
    }
    else{
    child = new TrieNode(word[0]);
    root->childCount++;
    root->children[index] = child;
    }
    insertUtil(child, word.substr(1));
    }
    void insertWord(string word){
    insertUtil(root,word);
    }
    void lcp(string str, string& ans){
    for(int i=0;ichildCount == 1){
    ans.push_back(ch);
    int index = ch-'a';
    root=root->children[index];
    }
    else
    break;
    if(root->isTerminal)
    break;
    }
    }
    };
    class Solution {
    public:
    string longestCommonPrefix(vector& strs) {
    Trie* t = new Trie();
    for(auto i:strs){
    if(i == "") return "";
    t->insertWord(i);
    }
    string first = strs[0];
    string ans = "";
    t->lcp(first,ans);
    return ans;
    }
    };
    // ❤

  • @studywithme66
    @studywithme66 2 ปีที่แล้ว

    Yes sir hum kar rahe hai abhi se

  • @abhisheksameer1842
    @abhisheksameer1842 2 ปีที่แล้ว

    maja aa rha

  • @vivan1852
    @vivan1852 2 ปีที่แล้ว

    Attendance done ,

  • @BhaiRayyanKiDuniya
    @BhaiRayyanKiDuniya 2 ปีที่แล้ว

    maza agya

  • @govindsuryavanshi6653
    @govindsuryavanshi6653 ปีที่แล้ว

    First I have completed all DSA series and now conclude this is Greatest ever DSA series to exists on youtube or paid courses. Your contribution will be remembered. You're God of DSA for us🙇‍♂ Thanks you.