Created
August 5, 2021 07:44
-
-
Save sritasngh/e6398a95e49a35d9d8d7ece78aefe9a2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include | |
int funn(int n, vector<int> arr) | |
{ | |
// 1 1 2 4 | |
int op=0; | |
int sum=0; | |
bool flag=false; | |
while(1){ | |
if(flag){ | |
sum=0; | |
for_each(arr.begin(), arr.end(), [&](int j){j/=2; if(j%2){flag=false;} sum+=j;}); | |
op++; | |
} | |
else{ | |
for(int i=0; i<n; i++){ | |
// check for odd | |
sum=0; | |
if(arr[i]%2){ | |
for_each(arr.begin(),arr.end(),[&](int k){if(k%2) {k--} op++; sum+=k;}) | |
flag =true; | |
break; | |
} | |
} | |
flag=true; | |
if(!sum){ | |
break; | |
} | |
} | |
return op; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment