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.
OK, so this was fairly challenging for me. I first pig-headedly went down the route of adding chocolates to all colleagues but one, and got partially there, but that was real hard and convoluted, and cases 11,12,13, and 15 were still failing.
I then went back to this comment and accepted the idea that adding chocolates to all but one was equivalent to removing the same amount of chocolates to one colleague only. Way easier to write and read, but still the same cases were failing. So I read again the end of the comment about getting the minimum value from ops[i]=sum(f(c-min+i)), with i in {0,1,2,3,4}. And the resulting code passed all tests.
But for the life of me I cannot figure out why by varying i between 0 and 4 we can get a better output. I'm guessing 4 because 4 is the last integer before 5, but that doesn't cut it.
Could someone explain in layman terms why we should run 5 variations to obtain the best result please?
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Equal
You are viewing a single comment's thread. Return to all comments →
OK, so this was fairly challenging for me. I first pig-headedly went down the route of adding chocolates to all colleagues but one, and got partially there, but that was real hard and convoluted, and cases 11,12,13, and 15 were still failing. I then went back to this comment and accepted the idea that adding chocolates to all but one was equivalent to removing the same amount of chocolates to one colleague only. Way easier to write and read, but still the same cases were failing. So I read again the end of the comment about getting the minimum value from ops[i]=sum(f(c-min+i)), with i in {0,1,2,3,4}. And the resulting code passed all tests. But for the life of me I cannot figure out why by varying i between 0 and 4 we can get a better output. I'm guessing 4 because 4 is the last integer before 5, but that doesn't cut it. Could someone explain in layman terms why we should run 5 variations to obtain the best result please?