Distribute Money to Maximum Children

You are given an integer money denoting the amount of money in dollars that you have and another integer children denoting the number of children that you must distribute the money to.

You have to distribute the money according to the following rules:

  • All money must be distributed.
  • Everyone must receive at least 1 dollar.
  • Nobody receives 4 dollars.

Return the maximum number of children who may receive exactly 8 dollars if you distribute the money according to the aforementioned rules. If there is no way to distribute the money, return -1.

Example 1
Inputmoney = 20, children = 3
Output1
The maximum number of children with 8 dollars is 1; for example, the distribution can be 8, 9, and 3 dollars, and no distribution gives more children exactly 8 dollars.
Example 2
Inputmoney = 16, children = 2
Output2
Each child can be given exactly 8 dollars.

Constraints

  • 1 <= money <= 200
  • 2 <= children <= 30

Asked at 4 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate