If the ith element is j then we can have any value from small to j for the i - 1 th element We choose the one that requires the minimum operations
minimum = Math . Min ( minimum , dp [ i - 1 , j ] ) ; dp [ i , j ] = minimum + Math . Abs ( ar [ i ] - j ) ; } }