• + 0 comments

    So basically what he did in mathematical terms is

    1. He differentiated the function, found the change in array keys like +100, -100 etc. :-

      arr[lower-1]+=sum;
      
      if(upper < n) arr[upper]-=sum; 
      
    2. Then he integrated the derivated function to get the original function value at different points and found the max value:-

           for(int i=0;i<n;i++){
                               temp += arr[i];
                                  if(temp> max) max=temp;
                      }