Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intermediate Accounting

Authors: Donald E. Kieso, Jerry J. Weygandt, And Terry D. Warfield

13th Edition

9780470374948, 470423684, 470374942, 978-0470423684

More Books

Students also viewed these Accounting questions

Question

Would this individual be eligible for rehire? Why or why not? P968

Answered: 1 week ago