Finish the Orange Supply in the Fewest Days

Quick Overview

Finish the Orange Supply in the Fewest Days. Start with n oranges. Each day choose one available action: eat one orange; when the current count is divisible by two, eat half; or when it is divisible by three, eat two thirds.

Finish the Orange Supply in the Fewest Days

Company: Amazon

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Other

### Problem Start with `n` oranges. Each day choose one available action: eat one orange; when the current count is divisible by two, eat half; or when it is divisible by three, eat two thirds. Return the minimum days needed to leave no oranges. ```cpp class Solution { public: int minDays(int n); }; ``` ### Examples **Example 1:** ```text n = 8 Output: 4 Explanation: Counts can change 8 -> 4 -> 2 -> 1 -> 0. ``` **Example 2:** ```text n = 12 Output: 4 Explanation: Counts can change 12 -> 4 -> 2 -> 1 -> 0. The smallest count reachable after two days is 2, so a third day still cannot finish. The displayed four-day route is optimal. ``` ### Constraints - `1 <= n <= 2 * 10^9`. ### Clarifying Questions Divisibility is tested against the count at the start of that day. A division action consumes a whole day, just as eating one orange does. ```hint Inspect the structure At what moment is divisibility checked, and how many days does each chosen action consume? ``` ### Reasoning checkpoints - Account for the divisibility condition and one-day cost of each allowed action. - Prove the minimum-day claim and explain how resource use scales up to `2 * 10^9` oranges. ### Optional extensions How does memoization compare with a table indexed by every count up to `n`?

Overview: Finish the Orange Supply in the Fewest Days. Start with n oranges. Each day choose one available action: eat one orange; when the current count is divisible by two, eat half; or when it is divisible by three, eat two thirds.

Amazon logo
Amazon
Source window: 0–6 months · as of Oct 21, 2026
hardSoftware EngineerOtherCoding & Algorithms
0
0

Problem

Start with n oranges. Each day choose one available action: eat one orange; when the current count is divisible by two, eat half; or when it is divisible by three, eat two thirds. Return the minimum days needed to leave no oranges.

class Solution {
public:
    int minDays(int n);
};

Examples

Example 1:

n = 8
Output: 4
Explanation: Counts can change 8 -> 4 -> 2 -> 1 -> 0.

Example 2:

n = 12
Output: 4
Explanation: Counts can change 12 -> 4 -> 2 -> 1 -> 0. The smallest count reachable after two days is 2, so a third day still cannot finish. The displayed four-day route is optimal.

Constraints

  • 1 <= n <= 2 * 10^9 .

Clarifying Questions Guidance

Divisibility is tested against the count at the start of that day. A division action consumes a whole day, just as eating one orange does.

Reasoning checkpoints

  • Account for the divisibility condition and one-day cost of each allowed action.
  • Prove the minimum-day claim and explain how resource use scales up to 2 * 10^9 oranges.

Optional extensions

How does memoization compare with a table indexed by every count up to n?