Cost of painting n * m grid | Java implementation of the approach ; Function to return the minimum cost ; Driver code
class gfg { static int getMinCost ( int n , int m ) { int cost = ( n - 1 ) * m + ( m - 1 ) * n ; return cost ; } public static void main ( String [ ] args ) { int n = 4 , m = 5 ; System . out . println ( getMinCost ( n , m ) ) ; } }