We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 989bf93 commit 644071dCopy full SHA for 644071d
Dynamic Programming/2D/Subsequences/AssignCookies.java
@@ -0,0 +1,33 @@
1
+class AssignCookies { // 2D - DP Approach
2
+ public int findContentChildren(int[] g, int[] s) {
3
+
4
+ Arrays.sort(g);
5
+ Arrays.sort(s);
6
7
+ int n = g.length;
8
+ int m = s.length;
9
10
+ int[][] dp = new int[n+1][m+1];
11
12
+ // for(int i = 0; i<n; i++){ //Bases cases
13
+ // dp[i][0] = 0;
14
+ // }
15
16
+ // for(int j = 0; j<m; j++){
17
+ // dp[0][j] = 0;
18
19
20
+ for(int i = 1; i<n+1; i++){
21
+ for(int j = 1; j<m+1; j++){
22
+ if(s[j-1]>=g[i-1]){
23
+ dp[i][j] = Math.max(dp[i-1][j], 1+dp[i-1][j-1]);
24
+ }
25
+ else{
26
+ dp[i][j] = dp[i-1][j];
27
28
29
30
31
+ return dp[n][m];
32
33
+}
0 commit comments