491. Maximum Number of Combo Meals From Menu Sections
Maximum Number of Combo Meals From Menu Sections

A food truck is planning a menu with exactly totalDishes different dishes.

All the dishes must be grouped into at least two menu sections, such as Starters, Mains and Drinks. Every dish goes into exactly one section, and every section must contain at least one dish.

A combo meal is made by choosing one dish from each section. For example, a menu with 2 starters and 3 mains offers 2 × 3 = 6 different combo meals.

Return the maximum number of different combo meals the food truck can offer.

Method Signature

int maxComboMeals(int totalDishes)

  • totalDishes is the number of different dishes on the menu.
  • Choose section sizes s1, s2, ..., sk where k ≥ 2, every si ≥ 1, and s1 + s2 + ... + sk = totalDishes.
  • Return the maximum possible value of s1 × s2 × ... × sk.

Constraints

  • 2 ≤ totalDishes ≤ 58
  • The answer always fits in a 32-bit signed integer.

Examples

Example 1

maxComboMeals(totalDishes = 4)

Output: 4

Explanation: Two sections with 2 dishes each give 2 × 2 = 4 combo meals. Sections of 1 and 3 dishes give only 3. Putting all 4 dishes in one section is not allowed.

Example 2

maxComboMeals(totalDishes = 5)

Output: 6

Explanation: Sections of 2 and 3 dishes give 2 × 3 = 6 combo meals.

Example 3

maxComboMeals(totalDishes = 9)

Output: 27

Explanation: Three sections of 3 dishes each give 3 × 3 × 3 = 27 combo meals. Sections of 4 and 5 dishes give only 20.

Example 4

maxComboMeals(totalDishes = 14)

Output: 162

Explanation: Sections of 3, 3, 3, 3 and 2 dishes give 3 × 3 × 3 × 3 × 2 = 162 combo meals. Sections of 3, 3, 4 and 4 dishes give only 144.



Please use Laptop/Desktop or any other large screen to add/edit code.