> For the complete documentation index, see [llms.txt](https://mayanktyagi3111.gitbook.io/interview-prep/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mayanktyagi3111.gitbook.io/interview-prep/dynamic-programming/minimum-number-of-days-to-eat-n-oranges.md).

# Minimum Number of Days to Eat N Oranges

There are `n` oranges in the kitchen and you decided to eat some of these oranges every day as follows:

* Eat one orange.
* If the number of remaining oranges (`n`) is divisible by 2 then you can eat  n/2 oranges.
* If the number of remaining oranges (`n`) is divisible by 3 then you can eat  2\*(n/3) oranges.

You can only choose one of the actions per day.

Return the minimum number of days to eat `n` oranges.

**Example 1:**

```
Input: n = 10
Output: 4
Explanation: You have 10 oranges.
Day 1: Eat 1 orange,  10 - 1 = 9.  
Day 2: Eat 6 oranges, 9 - 2*(9/3) = 9 - 6 = 3. (Since 9 is divisible by 3)
Day 3: Eat 2 oranges, 3 - 2*(3/3) = 3 - 2 = 1. 
Day 4: Eat the last orange  1 - 1  = 0.
You need at least 4 days to eat the 10 oranges.
```

**Example 2:**

```
Input: n = 6
Output: 3
Explanation: You have 6 oranges.
Day 1: Eat 3 oranges, 6 - 6/2 = 6 - 3 = 3. (Since 6 is divisible by 2).
Day 2: Eat 2 oranges, 3 - 2*(3/3) = 3 - 2 = 1. (Since 3 is divisible by 3)
Day 3: Eat the last orange  1 - 1  = 0.
You need at least 3 days to eat the 6 oranges.
```

**Example 3:**

```
Input: n = 1
Output: 1
```

**Example 4:**

```
Input: n = 56
Output: 6
```

**Constraints:**

* `1 <= n <= 2*10^9`

```java
class Solution {
    Map<Integer, Integer> map;

    public int minDays(int n) {
        map = new HashMap<>();
        return helper(n);
    }

    private int helper(int n) {
        if (n <= 1)
            return n;
        if (map.containsKey(n))
            return map.get(n);
        int ans = Integer.MAX_VALUE;
        // 1 -> Divide step, n%2 or n%3 represents the steps of -1
        // to reach the closest multiple or 2 or 3
        ans = Math.min(ans, helper(n / 2) + n % 2 + 1);
        ans = Math.min(ans, helper(n / 3) + n % 3 + 1);
        map.put(n, ans);
        return ans;
    }
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://mayanktyagi3111.gitbook.io/interview-prep/dynamic-programming/minimum-number-of-days-to-eat-n-oranges.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
