one-line-wonders icon indicating copy to clipboard operation
one-line-wonders copied to clipboard

Combinations

Open lelchan opened this issue 5 years ago • 3 comments

You are given an array with random integers. Design an algorithm that returns a list of arrays with all the possible combinations of the numbers in the array. This means if the input is [1,2,3], the output will be [[1],[2],[3],[12],[13],[23],[123]].

Some solutions might be faster than others but speed does not matter.

lelchan avatar Oct 08 '19 16:10 lelchan

Solved it Please check if changes let me know https://github.com/wzhouwzhou/one-line-wonders/pull/383

yashagarwal1999 avatar Oct 08 '19 17:10 yashagarwal1999

Please see my comments

wzhouwzhou avatar Oct 08 '19 20:10 wzhouwzhou

Solved it in Javascript. This kind of combination is known as a power set and I found more information about it on wikipedia.

It's very inefficient but that's usually the case with complex javascript one-liners. 😄

DiscoTiger avatar Oct 24 '19 20:10 DiscoTiger