Make array elements equal in Minimum Steps | C ++ program to make the array elements equal in minimum steps ; Returns the minimum steps required to make an array of N elements equal , where the first array element equals M ; Corner Case 1 : When N = 1 ; Corner Case 2 : When N = 2 else if ( N == 2 ) corner case 2 ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int steps ( int N , int M ) { if ( N == 1 ) return 0 ; return M ; return 2 * M + ( N - 3 ) ; } int main ( ) { int N = 4 , M = 4 ; cout << steps ( N , M ) ; return 0 ; }