is there is some algorithm to find the fast method of "sum of differences of each elements in an array upto 10^9…