I got this question today in Online Technical Exam. Of 3 question I was able to solve 2 but stuck in this. I am not even sure I understand the problem correctly. For example(read question first) in 2nd testcase bob can have 2 pack of 2 chocolate each and 1 remaining.
I am hoping you can guide me in right direction.
Bob handles the jobs of packaging at a chocolate shop, Bob has N chocolates, and needs to decide how many chocolates to place in each package.
Each package must contain the same number of chocolates Bob will choose an integer A between 1 and N, inclusive, and place exactly A chocolates into each package
Bob makes as many packages as possible and then gets to eat the remaining chocolates. Bob enjoys eating chocolates. Help Bob choose the package such that will let him eat as many chocolates as possible.
Input: N (The number of chocolates came for packaging)
Output: A (The package size that will maximize the number of leftover chocolates. If multiple package sizes will result in the same number of leftover chocolates, print the largest such size.)
Examples:
Input: 2
Output: 2
Explanation: There will be no leftover chocolates, regardless of the size Bob chooses.
Input: 5
Output: 3 Explanation: There will be 2 leftover chocolates.
Update :
solution is floor(N/2)+1