We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
voidcalculate_the_maximum(intn,intk){//Write your code here.intnumbersToConsider[n];//Numbers in answer array will represent biggest and, or, xor in sequenceintanswer[3]={0,0,0};//Making an array of numbers from 1 to nfor(inti=0;i<n;i++){numbersToConsider[i]=i+1;}for(inti=0;i<numbersToConsider[n-1];i++){for(intj=1;numbersToConsider[i]+j<=n;j++){intand;and=numbersToConsider[i]&numbersToConsider[i+j];if(and>answer[0]&&and<k){answer[0]=and;}intor;or=numbersToConsider[i]|numbersToConsider[i+j];if(or>answer[1]&&or<k){answer[1]=or;}intxor;xor=numbersToConsider[i]^numbersToConsider[i+j];if(xor>answer[2]&&xor<k){answer[2]=xor;}}}printf("%d\n%d\n%d",answer[0],answer[1],answer[2]);}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Bitwise Operators
You are viewing a single comment's thread. Return to all comments →