Pergunta de entrevista da empresa Two Sigma

print all the subsets of set

Resposta da entrevista

Sigiloso

22 de set. de 2012

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.