From 58b85d23dd93e794449a2a28ecde08f35561b4b0 Mon Sep 17 00:00:00 2001 From: stud203788 Date: Fri, 17 Apr 2026 17:18:26 +0300 Subject: [PATCH] Implement llongest_increasing_subsequence function --- solution21.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/solution21.py b/solution21.py index 6152ca6..ed5588d 100644 --- a/solution21.py +++ b/solution21.py @@ -1,2 +1,13 @@ def llongest_increasing_subsequence(arr: list) -> list: - pass + if not arr: + return [] + dp = [[x] for x in arr] + for i in range(len(arr)): + for j in range(i): + if arr[j] < arr[i] and len(dp[j]) + 1 > len(dp[i]): + dp[i] = dp[j] + [arr[i]] + return max(dp, key = len) + + print(dp) +if __name__ == "__main__": + print(f"llongest_increasing_subsequence([10, 9, 2, 5, 3, 7, 101, 18] -> {llongest_increasing_subsequence([10, 9, 2, 5, 3, 7, 101, 18])}")