From 950d7c2ca1cfbb4ef3db3f9077d40969ee4f732f Mon Sep 17 00:00:00 2001 From: KBoumghar Date: Wed, 1 Nov 2023 02:31:44 -0400 Subject: [PATCH] Added Longest Strictly Increasing subsequence, python --- .../LongestStrictlyIncreasingSubsequence.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 INterviewQuestions/LongestStrictlyIncreasingSubsequence.py diff --git a/INterviewQuestions/LongestStrictlyIncreasingSubsequence.py b/INterviewQuestions/LongestStrictlyIncreasingSubsequence.py new file mode 100644 index 00000000..3018b3d2 --- /dev/null +++ b/INterviewQuestions/LongestStrictlyIncreasingSubsequence.py @@ -0,0 +1,19 @@ +""" +Given a list of integers, find the length of the longest strictly increasing subsequence in the list +""" +def longestIncreasing(arr): + from bisect import bisect_left + tmp = [] + + for v in arr: + if len(tmp) == 0: + tmp.append(v) + + elif v < tmp[-1]: + element_replace = bisect_left(tmp, v) + tmp[element_replace] = v + + else: + tmp.append(v) + + return len(tmp)