google | mtv | phone screen | failed
Anonymous User
607

Given an int[] nums and k, return all possible permutation of k numbers

ex
int[] nums = {1, 2, 3}; no dup

k = 2
output no dup in the each result list
print [[2,1],[1,2],[3,1],[1,3],[3,2],[2,3]]
backtracking is easy, can you solve it Iteratively

followup,
what is if the same number in the array can be used move than once

print [2,1],[1,2],[3,1],[1,3],[3,2],[2,3], [1, 1], [2, 2], [3, 3]

can you solve it Iteratively

Comments (3)