File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed
src/Dynamic_Programming/Longest_Common_SubString Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments