Message on Whatsapp 8879355057 for DSA(OA + Interview) + Fullstack Dev Training + 1-1 Personalized Mentoring to get 10+LPA Job
0 like 0 dislike
1,279 views
in Online Assessments by Expert (46,090 points) | 1,279 views

1 Answer

0 like 0 dislike
Best answer

image

image

IMAGES OF QUES 

 

by Expert (46,090 points)
selected by
0 0
does this solution will work?
#include<iostream>
#include<bits/stdc++.h>
using namespace std;


int main()
{
    //find x such that (a^x)*(b^x) is maximum
    // and x should be less than pow(2,n);
    int a=12;
    int b=7;
    int n=4;
    int range=pow(2,n);
    int maxprod=INT_MIN;
    int ans=0;
     
     int low=0,high=range-1;
     while(low<=high)
     {
        int mid=low+(high-low)/2;
         int prod=(a^mid)*(b^mid);
        if(prod>=maxprod)
        {
            maxprod=prod;
            ans=low;
            high=mid-1;
        }
        else {
            low=mid+1;
        }

     }
     cout<<ans;
}
0 0
Dusre questions bhi add Karo plz.