Skip to content

Instantly share code, notes, and snippets.

View AGBrown's full-sized avatar

Andrew Brown AGBrown

View GitHub Profile
@AGBrown
AGBrown / SubsetSum.cs
Created March 18, 2018 19:38 — forked from riyadparvez/SubsetSum.cs
Implementation of subset sum problem using dynamic programming approach in C#.
public static bool SubsetSum(IEnumerable<int> list, int s)
{
var arr = list.ToArray();
Array.Sort(arr);
var a = arr.Where(i => i < 0).Sum();
var b = arr.Where(i => i > 0).Sum();
if(a > s || b < s)
{
return false;
}