File tree 1 file changed +12
-5
lines changed
src/main/java/com/thealgorithms/dynamicprogramming
1 file changed +12
-5
lines changed Original file line number Diff line number Diff line change 4
4
given array sums up to a specific target value.
5
5
*/
6
6
public final class SubsetSumSpaceOptimized {
7
- /*
8
- Space Optimized solution using 1D boolean array
9
- Time Complexity: O(n * sum)
10
- Space complexity: O(sum)
11
- */
7
+ private SubsetSumSpaceOptimized (){
8
+ }
9
+ /**
10
+ * This method checks whether the subset of an array
11
+ * contains a given sum or not. This is an space
12
+ * optimized solution using 1D boolean array
13
+ * Time Complexity: O(n * sum), Space complexity: O(sum)
14
+ *
15
+ * @param arr An array containing integers
16
+ * @param sum The target sum of the subset
17
+ * @return True or False
18
+ */
12
19
public static boolean isSubsetSum (int [] arr , int sum ) {
13
20
int n = arr .length ;
14
21
// Declare the boolean array with size sum + 1
You can’t perform that action at this time.
0 commit comments