using System.Collections.Generic;
combinationSum(List<int> arr, int sum)
= new List<List<int> >();
List<int> temp = new List<int>();
HashSet<int> set = new HashSet<int>(arr);
findNumbers(ans, arr, sum, 0, temp);
findNumbers(List<List<int> > ans,
List<int> arr, int sum, int index,
ans.Add(new List<int>(temp));
for (int i = index; i < arr.Count; i++) {
if ((sum - arr[i]) >= 0) {
findNumbers(ans, arr, sum - arr[i], i,
public static void Main()
List<int> arr = new List<int>();
= combinationSum(arr, sum);
Console.WriteLine("Empty");
for (int i = 0; i < ans.Count; i++) {
for (int j = 0; j < ans[i].Count; j++) {
private static void permute(String str,
for (int i = l; i <= r; i++)
public static String swap(String a,
char[] charArray = a.ToCharArray();
charArray[i] = charArray[j];
string s = new string(charArray);