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.
some one may get the same issue.
* First Code's logic is correct but it fails for some test cases, becuase of total cost is computed on all intgers (b, bc, w, wc, z), not on the long data types.
longtaumBday(intb,intw,intbc,intwc,intz){// Check if converting black to white or white to black is cheaperif(bc>wc+z){return(b*(wc+z))+(w*wc);}elseif(wc>bc+z){return(b*bc)+(w*(bc+z));}else{// If neither conversion is cheaper, buy gifts at original pricesreturn(b*bc)+(w*wc);}}***CorrectSolution:***longtaumBday(intb,intw,intbc,intwc,intz){// Check if converting black to white or white to black is cheaperif(bc>wc+z){return(b*(wc+z))+(w*wc);}elseif(wc>bc+z){return(b*bc)+(w*(bc+z));}else{// If neither conversion is cheaper, buy gifts at original pricesreturn(b*bc)+(w*wc);}}// see the most optimized code in the below solution, written by @alban_tyrex
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Taum and B'day
You are viewing a single comment's thread. Return to all comments →
some one may get the same issue. * First Code's logic is correct but it fails for some test cases, becuase of total cost is computed on all intgers (b, bc, w, wc, z), not on the long data types.