For Example - If given array is :- int[] arr = { 1, 4, 8, 3 };
The result Subarray should be:
1 ,
1 ,4 ,
1 ,4 ,8 ,
1 ,4 ,8 ,3 ,
4 ,
4 ,8 ,
4 ,8 ,3 ,
8 ,
8 ,3 ,
3 ,
and than , Maximum of each subarray are :- 1 ,4 ,8,8,4,8,8,8,8,3 therefore sum of all maximum should be :- 1 + 4 +8+8+4+8+8+8+8=3 = 60
To Write Subarray, I was able to do this with loop:-
{
for(int j = i ; j <= n ; j++)
{
for(int k = i ; k < j ; k++)
{
Console.Write(arr[k] + " ," );
}
Console.WriteLine(" " );
}
}
}
After this, I was trying to store maximum values in the Dictionary data structure but was not able to find where exactly use dictionary structure and how to use Math.max statement.
IDictionary<int, int> maxValue = new Dictionary<int, int>();