Java: Combinational Sum

Level : Intermediate
Mentor: Shailendra Chauhan
Type : GuidedLab
Points : 10
Duration : 00:30:00

Lab Details

Problem Statement:

Given an array of positive integers arr[] and an integer x, The task is to find all unique

combinations in arr[] where the sum is equal to x.

The same repeated number may be chosen from arr[] an unlimited number of times. Elements

in a combination (a1, a2, …, ak) must be printed in non-descending order. (ie, a1 <= a2 <= … <=

ak). If there is no combination possible print “Empty”.

Example:

Input:

arr[] = 2, 4, 6, 8, x = 8
2, 2, 2]2, 2, 4]2, 6]4, 4][8]

Output:

[2, 2, 2, 2]
[2, 2, 4]
[2, 6]
[4, 4]
[8]
Self-paced Membership
  • 22+ Video Courses
  • 800+ Hands-On Labs
  • 400+ Quick Notes
  • 55+ Skill Tests
  • 45+ Interview Q&A Courses
  • 10+ Real-world Projects
  • Career Coaching Sessions
  • Email Support
Upto 60% OFF
Know More
Still have some questions? Let's discuss.
CONTACT US
Accept cookies & close this