File tree Expand file tree Collapse file tree 1 file changed +12
-5
lines changed
src/main/java/com/thealgorithms/dynamicprogramming Expand file tree Collapse file tree 1 file changed +12
-5
lines changed Original file line number Diff line number Diff line change 44given array sums up to a specific target value.
55*/
66public 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+ */
1219 public static boolean isSubsetSum (int [] arr , int sum ) {
1320 int n = arr .length ;
1421 // Declare the boolean array with size sum + 1
You can’t perform that action at this time.
0 commit comments