Created
December 8, 2016 23:57
-
-
Save daviscodesbugs/cffd05431cce033606f5b898137a3037 to your computer and use it in GitHub Desktop.
Interview Questions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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