Question
Write a Java program, that given an array of ints and a desiredtarget sum returns the set of combinations of any length that add up
Write a Java program, that given an array of ints and a desiredtarget sum returns the set of
combinations of any length that add up to that targetsum.
Each set of combinations must be specified by the indexes (0-based)of the integers. See
examples below.
The code snippet below is pseudo-code and not Java.
EXAMPLE 1:
==============
total_combinations = calculate_combinations(input=[5, 5, 15, 10],target_sum=15)
ANSWER 1:
==============
should return 3 sets, as there are 3 combinations of numbers fromthe input array that add up
to 15, namely:
[2] =>input[2] = 15
[0, 3] => input[0]= 5, input[3] = 10, sum = 15
[1, 3] => input[1]= 5, input[3] = 10, sum = 15
EXAMPLE 2:
==============
total_combinations = calculate_combinations(input=[1, 2, 3, 4, 5,6], target_sum=6)
ANSWER 2:
==============
should return 2 sets, as there are 2 combinations of numbers fromthe input array that add up
to 6, namely:
[0, 1, 2]
[1, 3]
[5]
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started