From 23595e9524b21035ae6de8ac72736a882cdb33c4 Mon Sep 17 00:00:00 2001 From: Radhika Bansal <96312216+Radhika403@users.noreply.github.com> Date: Mon, 7 Feb 2022 20:28:35 +0530 Subject: [PATCH] chore(Java): add target-sum-subsets problem (#687) --- .../Java/backtracking/target-sum-subsets.java | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 algorithms/Java/backtracking/target-sum-subsets.java diff --git a/algorithms/Java/backtracking/target-sum-subsets.java b/algorithms/Java/backtracking/target-sum-subsets.java new file mode 100644 index 00000000..6a386554 --- /dev/null +++ b/algorithms/Java/backtracking/target-sum-subsets.java @@ -0,0 +1,49 @@ +// Target sum subsets is a program to print all subsets of an array (given by user) such that sum of all elements in subset equal to a target sum given by user + +// Algorithm Type: Backtracking +// Time Complexity: O(2^N) + +import java.io.*; +import java.util.*; + +public class targetSumSubsets { + + public static void main(String[] args) throws Exception { + Scanner scn = new Scanner(System.in); + + // input size of array + int n = scn.nextInt(); + + // input elements of array + int[] arr = new int[n]; + for(int i=0; i