diff --git a/Dynamic Programming/LongestIncreasingSubsequence.java b/Dynamic Programming/LongestIncreasingSubsequence.java new file mode 100644 index 0000000..e1821e7 --- /dev/null +++ b/Dynamic Programming/LongestIncreasingSubsequence.java @@ -0,0 +1,42 @@ +import java.util.ArrayList; +import java.util.List; + +public class LIS { + public static int lowerBound(List a, int low, int high, int element){ + while(low < high){ + int middle = low + (high - low)/2; + if(element > a.get(middle)) + low = middle + 1; + else + high = middle; + } + return low; + } + + public static int upperBound(List a, int low, int high, int element){ + while(low < high){ + int middle = low + (high - low)/2; + if(a.get(middle) > element) + high = middle; + else + low = middle + 1; + } + return low; + } + + public static int longestIncreasingSubsequence(List a){ + //equals included then upperbound + // else lower bound use as required + ArrayList ans = new ArrayList<>(); + for(int i=0;ians.size()){ + ans.add(a.get(i)); + } + else + ans.set(x,a.get(i)); + } + return ans.size(); + } + +} \ No newline at end of file