Skip to content

Commit b098215

Browse files
committed
Three-Hundred-Seven Commit: Add Minimum Deletions to Make a Sequence Sorted problem to Longest Common Substring section
1 parent 9c186b7 commit b098215

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package Dynamic_Programming.Longest_Common_SubString;
2+
3+
// Problem Statement: Minimum Deletions to Make a Sequence Sorted
4+
// LeetCode Question:
5+
6+
public class Problem_7_Minimum_Deletions_To_Make_A_Sequence_Sorted {
7+
// Bottom-up Dynamic Programming
8+
public int findMinimumDeletions(int[] nums){
9+
// subtracting the length of LIS from the length of the input array to get minimum number of deletions
10+
return nums.length - findLISLength(nums);
11+
}
12+
13+
private int findLISLength(int[] nums) {
14+
int[] dp = new int[nums.length];
15+
dp[0] = 1;
16+
17+
int maxLength = 1;
18+
for (int i=1; i<nums.length; i++) {
19+
dp[i] = 1;
20+
for (int j=0; j<i; j++)
21+
if (nums[i] > nums[j] && dp[i] <= dp[j] ) {
22+
dp[i] = dp[j]+1;
23+
maxLength = Math.max(maxLength, dp[i]);
24+
}
25+
}
26+
return maxLength;
27+
}
28+
}

0 commit comments

Comments
 (0)