Two Sigma Interview Question: print all the subsets of set... | Glassdoor

Interview Question

Software Engineer Interview

print all the subsets of set


Interview Answer

1 Answer


on set of size n one can use binary representation of numbers from 0 to 2^n-1, where position of ones will tell you which elements to take. For example on 3 element set:
000 -empty set
001 -first element
010-second element
110-second and third element
111-the set itself.

AlexB on Sep 21, 2012

Add Answers or Comments

To comment on this, Sign In or Sign Up.