Complete the challenge. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 13

Complete the challenge.

Print the maximum combinations that can occur for the given letters. NOTE: Letters have to be taken in a character array and no digits or special characters are allowed. If so, warn the user to enter correct input. Ex: input - A B C output - A, B, C, AB, BC, AC, ABC. The order of the letters doesn't matter I.e., AB and BA are same. No need print them again. I think u people understand it better now. If u have any queries ask me. Send the answer as early as possible. Bkz, I need this in my project.

7th Oct 2017, 5:05 PM
VARUN KUMAR PADALA
VARUN KUMAR PADALA - avatar
10 Answers
+ 9
Can anyone be able to solve this in Java. Bkz, my project is done in Java.
8th Oct 2017, 2:17 AM
VARUN KUMAR PADALA
VARUN KUMAR PADALA - avatar
+ 8
Thanks for ur response. I'll give it a try.
8th Oct 2017, 2:23 AM
VARUN KUMAR PADALA
VARUN KUMAR PADALA - avatar
+ 6
Solved it. Have a look. And it's with Java... But only I have not checked for only letters. You can do that easily I think. https://code.sololearn.com/cb4XohDmM9Tw/?ref=app
8th Oct 2017, 5:36 AM
Sherlock
Sherlock - avatar
+ 5
very cool challenge! will indeed give it a try
7th Oct 2017, 5:30 PM
Murillo Pyaia
Murillo Pyaia - avatar
+ 5
I think condition is correct. Combination is a term of math. See https://en.wikipedia.org/wiki/Combination?wprov=sfla1 . I have other question to author. Is input array can include repeatly characters?
7th Oct 2017, 7:04 PM
Edward Fish
Edward Fish - avatar
+ 5
I think this program needs recursion and will be best with that. Wait I am trying it...
8th Oct 2017, 4:06 AM
Sherlock
Sherlock - avatar
+ 3
I am not that good in Java but this link may help you https://www.programcreek.com/2014/03/leetcode-combinations-java/
8th Oct 2017, 2:22 AM
Amr Ibrahim Khudair
Amr Ibrahim Khudair - avatar
+ 2
Hm, I think something is wrong with your condition. The maximum amount of combinations for A B C: A, B, C, AB, BA, AC, CA, BC, CB, ABC = 10. Am I right? //Edit Also ACB, BAC, BCA, CBA and CAB. So the maximum is 15
7th Oct 2017, 5:41 PM
Freezemage
Freezemage - avatar
7th Oct 2017, 7:58 PM
Amr Ibrahim Khudair
Amr Ibrahim Khudair - avatar
+ 1
Hi, what you can do is: if there are n letters, calculate in binary all the numbers between 0 and 111...1, where there are n 1's. Then, for each one of them (you can think they have n digits, maybe starting with some 0's), if in the position i appears a 1, then print the i-th letter given by the user, else, not print it. That way, you will get all the possible combinations of letters, including the void (if you don't want it, start in 000...01 instead 000...0). Hope it's useful!
2nd Aug 2020, 4:03 AM
Iván García Mestiza
Iván García Mestiza - avatar