Skip to content

Instantly share code, notes, and snippets.

@sritasngh
Created August 5, 2021 07:44
Show Gist options
  • Save sritasngh/e6398a95e49a35d9d8d7ece78aefe9a2 to your computer and use it in GitHub Desktop.
Save sritasngh/e6398a95e49a35d9d8d7ece78aefe9a2 to your computer and use it in GitHub Desktop.
#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