From 8fbb2f9d716474b56a925c0938db4682e334a5c1 Mon Sep 17 00:00:00 2001 From: Sukriti Shah Date: Fri, 20 Mar 2020 00:44:01 +0530 Subject: [PATCH] Assing PHP implementation for LIS --- Longest_Increasing_Subsequence/LIS.php | 44 ++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 Longest_Increasing_Subsequence/LIS.php diff --git a/Longest_Increasing_Subsequence/LIS.php b/Longest_Increasing_Subsequence/LIS.php new file mode 100644 index 0000000000..ba26b54b72 --- /dev/null +++ b/Longest_Increasing_Subsequence/LIS.php @@ -0,0 +1,44 @@ + $arr[$j] && $dp[$i] < $dp[$j] + 1) + $dp[$i] = $dp[$j] + 1; + } + + // find the max out of computed lengths of LIS + // ending at different indices + $max = PHP_INT_MIN; + for($i = 0; $i < $n; $i++){ + if($max < $dp[$i]) + $max = $dp[$i]; + } + + return $max; +} + +// Sample test case +$arr = array(3, 10, 2, 1, 20, 40, 60, 7); +$n = sizeof($arr); + +echo "Length of LIS is " , lisLen($arr, $n); + +/* +Sample Input as specified in the code: +3, 10, 2, 1, 20, 40, 60, 7 + +Sample Output: +Length of LIS is 5 +*/ + +?>