Meta Interview Question

Given a distinct set of integers, return all possible subsets.

Interview Answers

Anonymous

Jan 4, 2016

public static void subset(int[] disntictSet){ if(disntictSet==null || disntictSet.length==0){ return; } int N=disntictSet.length; int allMasks = (1 0) //The j-th element is used System.out.print((j + 1) + " "); } System.out.println(); } }

Anonymous

Jan 10, 2016

func Subsets(s: [Int])-> [[Int]] { var sortedSet = s sortedSet.quickSort() var result = [[Int]]() for item: Int in sortedSet { var temp = [[Int]]() for subset in result { temp.append(subset + [item]) } temp.append([item]) result += temp } result.append([Int]()) return result }