The sum of heights of the left side of a pyramid of height m is m(m-1)/2 and its same for the right portion. So they sum up to make m(m-1). Then just add the top most block to get m(m-1)+m=m²
Now if we had the sum of previous heights s, and final sum height m<=s, number of operations is definitely s-m²
Does this Solution takes the following input? - 1 2 5 5 1 - 1 2 5 4 7 - If not, why don’t they explicitly mention that there will be one largest number in the given array??
@chari407 for the order of m, we need to have 1, 2, 3, 4 …m and then m-1, m-2, m-3, m-4, …3, 2, 1
for 1 to m, (m*(m+1))/2 and for m -1 to 1 ((m-1)*m)/2 and u need to add both to get the answer which is m^2.