Interview questions where I start with "this might be solved by generating all possible combinations for the array elements" are usually meant to let me find something better.
Anyway I would like to add "I would definitely prefer another solution since this is O(X)".. the question is: what is the O(X) complexity of generating all combinations for a given set?
I know that there are n! / (n-k)!k! combinations (binomial coefficients), but how to get the big-O notation from that?
k
as constant? IsO(k!)
isO(1)
? If so, complexity isO(n^min{k,n-k})
. Otherwise - not sure you simplify it much. – Whipperink
is a constant, the complexity will beO(n^k)
, sincek < n-k
for a sufficiently largen
– Upthrust