I am solving a question on array manipulation on hackerrank. For a particular problem I write this solution. But this solution was ruled out due to timeout for some test cases. Can anyone help me with this please-
We are getting a 2d array(queries) in which each row has exactly three elements. Its First element is starting index and second element in ending index of our answer array. Third element is the number which we have to add in each element from starting index to ending index in answer array.
`
public static long arrayManipulation(int n, List<List<int>> queries)
{
long[] answer = new long[n];
foreach(var row in queries){
for(long i=row[0]; i<=row[1];i++)
{
answer[i-1]=answer[i-1]+row[2];
}
}
return answer.Max();
}