Course Hive
Search

Welcome

Sign in or create your account

Continue with Google
or
LeetCode 1143: Longest Common Subsequence — DP Explained (2D → O(n) Space)
Play lesson

LeetCode 75 C++ | Step-by-Step Solutions (LAN Academy) - LeetCode 1143: Longest Common Subsequence — DP Explained (2D → O(n) Space)

4.0 (1)
12 learners

What you'll learn

This course includes

  • 5.5 hours of video
  • Certificate of completion
  • Access on mobile and TV

Summary

Keywords

Full Transcript

LeetCode 1143. Longest Common Subsequence (LCS) — find the length of the longest subsequence common to two strings. In this video you’ll learn: The DP state and recurrence for LCS How the 2D DP table works (match vs skip) How to optimize space from O(m·n) to O(n) (rolling array) Time complexity and common pitfalls DP Idea Let dp[i][j] be the LCS length for prefixes text1[0..i-1] and text2[0..j-1]. Transition: If text1[i-1] == text2[j-1]: dp[i][j] = dp[i-1][j-1] + 1 Else: dp[i][j] = max(dp[i-1][j], dp[i][j-1]) Complexity Time: O(m·n) Space: O(m·n) (or O(n) optimized) If this helped, subscribe for more clean LeetCode explanations (DP, Greedy, Graphs). Leetcode playlist: https://www.youtube.com/playlist?list=PLF0G-7pZcOza_jyAxwMpa5KnK3vST5smK LAN Academy: youtube.com/channel/UCdKpV0t_sLv9gUsxHOYrt7g?sub_confirmation=1 #LeetCode #DynamicProgramming #CodingInterview #CPlusPlus #leetcodecoding #leetcodesolution #leetcodechallenge #faang #fang #computerscience #cs #codingtiktok #coding #codinglife #boostofhope #fyp #codinginterview #softwareengineer #swe #tech #foryou #python #learntocode #google #techtok #programming #algorithms #learntocode @reper #foryou #viral #reper #urmaritori #for

Course Hive

Continue this lesson in the app

Install CourseHive on Android or iOS to keep learning while you move.

FAQs

Course Hive
Download CourseHive
Keep learning anywhere