Project Euler #201: Subsets with a unique sum

  • + 0 comments

    Please find error in the code c#

    using System; using System.Collections.Generic; using System.IO; using System.Linq; class Solution { static void Main(String[] args) {

        int[] ar = Array.ConvertAll(Console.ReadLine().Split(' '), arTemp => Convert.ToInt32(arTemp));
        long[] arr = Array.ConvertAll(Console.ReadLine().Split(' '), arTemp => Convert.ToInt64(arTemp));
        long sum = 0;
        List<long> array = new List<long>();
            recorsiveSum(arr, 0, 0, 0, ar[1], ref array);
            var list= array.GroupBy(x => x)
               .Where(g => g.Count() == 1)
               .Select(y => y.Key)
               .ToList();
            sum = list.Sum();
            Console.WriteLine(sum);
    
    }
    
     static void  recorsiveSum(long[] arr, int ind, long sum,int m,int len, ref List<long> array)
        {
            long sum1 = 0;
            if (m == len)
            {
    
                m = 0;
                    array.Add(sum);
            }
            else
            {
                m++;
            }
    
            for (int i = ind; i < arr.Length; i++)
            {
                sum1 = sum;
                sum1 += arr[ind];
                ind++;
                recorsiveSum(arr, ind, sum1, m, len, ref array);
            }
    
        }
    

    }