Complete the code to initialize the dp array with 1s for each element.
int[] dp = new int[n]; for (int i = 0; i < n; i++) { dp[i] = [1]; }
Each element starts as a subsequence of length 1 by itself.
Complete the code to check if the current element can extend the subsequence ending at j.
if (arr[i] [1] arr[j]) { dp[i] = Math.max(dp[i], dp[j] + 1); }
We want to extend the subsequence only if current element is greater than previous.
Fix the error in the code to update the maximum length of LIS found so far.
int maxLen = 1; for (int i = 0; i < n; i++) { maxLen = Math.[1](maxLen, dp[i]); }
We want the maximum length, so use Math.max to update maxLen.
Fill both blanks to complete the nested loops for LIS calculation.
for (int i = [1]; i < n; i++) { for (int j = [2]; j < i; j++) { if (arr[i] > arr[j]) { dp[i] = Math.max(dp[i], dp[j] + 1); } } }
The outer loop starts from 1 because the first element is base case. Inner loop runs from 0 to i-1.
Fill all three blanks to create a map of element to its LIS length if length is greater than 1.
Map<Integer, Integer> lisMap = new HashMap<>(); for (int i = 0; i < n; i++) { if (dp[i] [1] 1) { lisMap.put(arr[[2]], dp[[3]]); } }
We add elements with LIS length greater than 1 to the map using their index i.
