Maximum number of multiplication by 3 or division by 2 operations possible on an array | C ++ program for the above approach ; Function to count maximum number of multiplication by 3 or division by 2 operations that can be performed ; Stores the maximum number of operations possible ; Traverse the array arr [ ] ; Iterate until arr [ i ] is even ; Increment count by 1 ; Update arr [ i ] ; Return the value of Count as the answer ; Driver Code ; Given Input ; Function Call
#include <bits/stdc++.h> NEW_LINE using namespace std ; int maximumTurns ( int arr [ ] , int N ) { int Count = 0 ; for ( int i = 0 ; i < N ; i ++ ) { while ( arr [ i ] % 2 == 0 ) { Count ++ ; arr [ i ] = arr [ i ] / 2 ; } } return Count ; } int main ( ) { int arr [ ] = { 5 , 2 , 4 } ; int M = 3 , K = 2 ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << maximumTurns ( arr , N ) ; return 0 ; }