There were 2 coding questions -
Find the maximum aggregate temperature changed evaluated among all the days.
ex - [-1,2,3] - 5
explanation -
[-1],[-1,2,3] - max(-1,4) = 4
[-1,2],[2,3] - max(1,5) = 5
[-1,2,3][3] - max(4,3) = 4
Find the power of each possible contiguous group of servers.
ex- [2,1,3] - 27
explanation -
power[0,0] = min(2)*sum([2]) = 4
power[0,1] = min(2,1)*sum([2,1]) = 3
power[0,2] = min(2,1,3)*sum([2,1,3]) =6
power[1,1] = min(1)*sum(1) = 1
power[1,2] = min(1,3)*sum([1,3]) = 4
power[2,2] = min(3)*sum([3]) = 9
overall sum = 27
Solved the second but got time limit exceeded for several test cases,couldn't solve the first one. Please tell the approach or answers for both the questions.
Thanks and happy coding.