Interview Questions

  • View all interview questions
  • blank
  • Print all subsets (power set) of a given set
    The input for this problem will be an array of numbers representing a set, which only contains unique numbers, and your goal is to print every possible set combination, otherwise known as the power set. For example: input set = [1, 2, 3] power set = [[], [1], [2], [3], [1, 2], [2, 3], [1, 3] [1, 2, 3]] The power set contains every possible combination of numbers. It also includes the empty set which contains no numbers from the original set.


    There will be 2N possible combinations of a set of length N because every element can either be in the set or not, which gives us 2 possibilities, and we do this for N numbers, giving us 2 * 2 * 2 ... = 2N.

    You need to be a premium member to see the rest of this question and code.

    Become a Premium Member

    With our large collection of challengs, tutorials, and solutions, we make it easy for you to become a better coder, prepare for interviews, and learn new skills from more experienced coders.

    β€œIt's been immensely helpful to get me where I am today.” ― kjalnes
    • 200+ Coding Challenges
    • Mock Interview Questions
    • 500,000+ Code Solutions
    • Algorithm Tutorials
    • Interview Prep Courses
    mrdaniel published this on 11/12/15 | array, math, subset, combination, Google, Facebook
  • +
  • 0
  • -
  • So in order to solve this one efficiently, do you recommend to use anything else ? For example Dynamic Programming ?
    Login to submit a comment