• + 3 comments

    The first loop was initializing the sum.

    The second loop was iterating through the list to calculate the sum of each subarray of size m by removing the first element and then adding the m'th element back. If that makes sense.

    I cleaned it up with Linq.

    static int birthday(List<int> s, int d, int m) {
        int sum = 0;
        int results = 0;
        for (int i = 0 ; i < s.Count() - m + 1 ; i++) {
            sum = s.Skip(i).Take(m).Sum();
            if (sum == d) {
                results++;
            }
        }
        return results;
    }