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 = min ( minimum , dp [ i - 1 ] [ j ] ) ; dp [ i ] [ j ] = minimum + abs ( ar [ i ] - j ) ; } }