Longest Common Subsequence | (C++, Java, Python) |30 day Challenge | Day 26 | LeetCode

Поділитися
Вставка
  • Опубліковано 19 вер 2024
  • Complete Playlist LeetCode Solutions: • LeetCode Solutions | L...
    *** Best Books For Data Structures & Algorithms for Interviews:*********
    1. Cracking the Coding Interview: amzn.to/2WeO3eO
    2. Cracking the Coding Interview Paperback: amzn.to/3aSSe3Q
    3. Coding Interview Questions - Narasimha Karumanchi: amzn.to/3cYqjkV
    4. Data Structures and Algorithms Made Easy - N. Karumanchi: amzn.to/2U8FrDt
    5. Data Structures & Algorithms made Easy in Java - N. Karumanchi: amzn.to/2U0qZgY
    6. Introduction to Algorithms - CLR - Cormen, Leiserson, Rivest: amzn.to/2Wdp8rZ
    *****************************************************************************
    LeetCode 30 day Challenge | Problem 26 | Longest Common Subsequence | 26 April,
    Facebook Coding Interview question,
    google coding interview question,
    leetcode,
    longest common subsequence,
    longest common subsequence c++,
    longest common subsequence python,
    longest common subsequence java,
    lcs,
    #Facebook #CodingInterview #LeetCode #30DayChallenge #Google #LCS #Amazon

КОМЕНТАРІ • 11

  • @yangiiu4347
    @yangiiu4347 4 роки тому +2

    Excellent video! It is a model for DP.

  • @victorkash4718
    @victorkash4718 3 роки тому +1

    what a beautiful explanation sir, thank you making this video

  • @williamwambua7710
    @williamwambua7710 4 роки тому +1

    So this was a dynamic problem.

  • @indranilthakur3605
    @indranilthakur3605 4 роки тому +1

    why do we keep all first row and column as 0 in the 2d array? The sole point of it to get the base case where none of it matches?

    • @KnowledgeCenter
      @KnowledgeCenter  4 роки тому

      First column means no character of text1 is selected. First row denotes no character of text2 is selected. You can get away with 1st row and column, and add a check in loop itself, if i == 0 or j == 0 then its 0.
      If we don't select select any character from any of the texts then there cannot be any common subsequence, i.e., length of LCS will be 0.

    • @indranilthakur3605
      @indranilthakur3605 4 роки тому +1

      @@KnowledgeCenter Also One thing I noticed, you created the 2D array of 7 rows and 6 columns[m+1][n+1] but created the matrix of 7 columns and 6 rows. t1 should be on y axis and t2 on x axis.

    • @indranilthakur3605
      @indranilthakur3605 4 роки тому +1

      @@KnowledgeCenter thanks

    • @KnowledgeCenter
      @KnowledgeCenter  4 роки тому +1

      Correct observation. Technically switching text1 and text2 from row to column & vice versa doesn't make a difference in result. But, Yes, I should have maintained consistency. While explaining I should have put text 1 as rows and text2 as columns.