Minimum Number of Days to Eat N Oranges

Hard Topics Company Tags

You have n oranges. Each day you must choose exactly one of the following actions:

  • Eat one orange.
  • If the current number of oranges is divisible by 2, eat half of them.
  • If the current number is divisible by 3, eat two thirds of them.

Return the fewest days needed to eat every orange.

Example 1:

Input: n = 3

Output: 2

Explanation: Eat two oranges on the first day using the divisible-by-3 action, then eat the last orange on the second day.

Example 2:

Input: n = 4

Output: 3

Explanation: Eat half to leave two oranges, then one orange on each of the next two days. Three days are necessary.

Example 3:

Input: n = 1

Output: 1

Explanation: Eat the only orange in one day.

Constraints:

  • 1 <= n <= 2000000000


Topics

Company Tags

Please upgrade to NeetCode Pro to view company tags.