Skip to content

Instantly share code, notes, and snippets.

@faiq
Last active December 3, 2015 00:20
Show Gist options
  • Save faiq/593fb2a26ff7185d3f68 to your computer and use it in GitHub Desktop.
Save faiq/593fb2a26ff7185d3f68 to your computer and use it in GitHub Desktop.

#Problem 1

Given a set of numbers, return all possible subsets for that set.

Example given the array [1,2,3,4]

You should return

[3 2 1] [3 2] [3 1] [3] [2 1] [2] [1] [] [4 3 2 1] [4 3 2] [4 3 1] [4 3] [4 2 1] [4 2] [4 1] [4]

It should be noted here that order does not matter, so [1,2] == [2,1]

#Problem 2

Given a set of numbers and a target print out all the numbers in that set that add up to the target

Example given the set [1, 100, 100, 50, 50, 50, 50, 50] and the target 200

You should return

[ (100 100) ]

Because that's the only pair that makes 200

#Problem 3

Given a set of letters, come up with a function that returns all the possible permutations of those letters

Example

Given the set of letters [t,h,e,y]

Return

they htey hety heyt tehy ethy ehty ehyt teyh etyh eyth eyht thye htye hyte hyet tyhe ythe yhte yhet tyeh yteh yeth yeht

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment