Skip to content

Instantly share code, notes, and snippets.

@daviscodesbugs
Created December 8, 2016 23:57
Show Gist options
  • Save daviscodesbugs/cffd05431cce033606f5b898137a3037 to your computer and use it in GitHub Desktop.
Save daviscodesbugs/cffd05431cce033606f5b898137a3037 to your computer and use it in GitHub Desktop.
Interview Questions
# Given an array, output all possible subsets
# An array of length n has 2^n subsets
def subsets(arr)
return [arr] if arr == []
subs = subsets(arr.drop(1))
subs + subs.map {|x| [arr.first] + x}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment