Skip to content

LeetCode 1143: Longest Common Subsequence #77

@github-actions

Description

@github-actions

LeetCode 1143: Longest Common Subsequence

Category: Dynamic Programming
Difficulty: See LeetCode
Solution File: src/dynamic_programming/longest_common_subsequence.py
Test File: tests/test_longest_common_subsequence.py

Problem Description

Given two strings text1 and text2, return the length of their longest common subsequence.
If there is no common subsequence, return 0.
A subsequence of a string is a new string generated from the original string with some characters
(can be none) deleted without changing the relative order of the remaining characters.

Example 1:
Input: text1 = "abcde", text2 = "ace"
Output: 3
Explanation: The longest common subsequence is "ace" and its length is 3.

Example 2:
Input: text1 = "abc", text2 = "abc"
Output: 3

Constraints:

  • 1 <= text1.length, text2.length <= 1000
  • text1 and text2 consist of only lowercase English characters

Tasks

  • Implement the solution in src/dynamic_programming/longest_common_subsequence.py
  • Ensure all test cases pass
  • Analyze time complexity
  • Analyze space complexity

Metadata

Metadata

Assignees

No one assigned

    Labels

    blind-75Blind 75 - Blind-75 problemsdynamic programmingBlind 75 - Dynamic Programming problems

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions