We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
public static int birthday(List<int> s, int d, int m)
{
//if required length is bigger than list length,
//END
if(m > s.Count)
{
return 0;
}
//if required length is eual to list length,
//then required sum must be equeal
if(m == s.Count && s.Sum() != d)
{
return 0;
}
//number of possible solutions
int result = 0;
//create sub-segments
for(int i = 0; i <= s.Count - m; i++)
{
int[] arr = new int[m];
s.CopyTo(i, arr, 0, m);
//check if sub segment has required sum
if(arr.ToList().Sum() == d)
{
result++;
}
}
return result;
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Subarray Division 1
You are viewing a single comment's thread. Return to all comments →
C#
}