Problem · Math

Minimum Cake Cuts

Learn this problem
EasyIDFC BankOA

Problem statement

You have cakes identical whole cakes and people people. Divide all of the cake equally so that every person receives exactly the same total amount.

A cut divides one existing cake piece into two pieces. Whole cakes and cut pieces may be distributed independently, and one person may receive multiple pieces.

Return the minimum number of cuts required.

Function

minimumCakeCuts(cakes: int, people: int) → int

Examples

Example 1

cakes = 2people = 6return = 4

Each person must receive one third of a cake. Cutting each cake into three equal pieces takes two cuts per cake, for 4 cuts total.

Example 2

cakes = 3people = 2return = 1

Give each person one whole cake, cut the remaining cake in half, and give one half to each person.

Constraints

  • 1 <= cakes <= 10^3
  • 1 <= people <= 10^3

More IDFC Bank problems

drafts saved locally
public int minimumCakeCuts(int cakes, int people) {
  // write your code here
}
cakes2
people6
expected4
checking account