I am currently trying to solve the task ‘SumOfMultiples’ in C#. My solution works perfectly in Visual Studio. But in Exercism I always get the error message:
Your tests timed out. This might mean that there was an issue in our infrastructure, but more likely it suggests that your code is running slowly. Is there an infinite loop or something similar?
Where is my error?
Here is my code:
public static class SumOfMultiples
{
public static int Sum(IEnumerable<int> multiples, int max)
{
HashSet<int> numbers = [];
foreach (int multiple in multiples)
{
for (int i = 1; multiple * i < max; i++)
{
numbers.Add(multiple * i);
}
}
return numbers.Sum();
}
}