<p>There are <code>n</code> oranges in the kitchen and you decided to eat some of these oranges every day as follows:</p>

<ul>
	<li>Eat one orange.</li>
	<li>If the number of remaining oranges <code>n</code> is divisible by <code>2</code> then you can eat <code>n / 2</code> oranges.</li>
	<li>If the number of remaining oranges <code>n</code> is divisible by <code>3</code> then you can eat <code>2 * (n / 3)</code> oranges.</li>
</ul>

<p>You can only choose one of the actions per day.</p>

<p>Given the integer <code>n</code>, return <em>the minimum number of days to eat</em> <code>n</code> <em>oranges</em>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> n = 10
<strong>Output:</strong> 4
<strong>Explanation:</strong> 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.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> n = 6
<strong>Output:</strong> 3
<strong>Explanation:</strong> 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.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= n &lt;= 2 * 10<sup>9</sup></code></li>
</ul>

'''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.
Given the integer n, return the minimum number of days to eat n oranges.

# optimal choice pattern problem 
    - need to minimize the result

# problem statement abservation
    - we have given an int n, we can perform 3 operations based on the condition,
        - if the n div // 2 :- the we have consume n  - n//2 a day 
        - if the n div // 3 :- the we can have n - 2* (n//3) a day
        - else we just consume only one and move forward 
    - we need to minixe the no of days we consume these oranges 

# solution approach 
    - when n reaches 0 then we have had every oranges:- base case
    - recursion relationship
        - perameter is just n 
            - action //2 ??? possible 
            - action //3 ??? possible
            - action n-1
            - for each aciton just need to add 1 with it will return the result at base case
        - by calling them inside the min func we can valid min out of them 
        - edges when n < 0: return float('inf') :- since you can't consuem oragens which is not existing right.'''


class Solution:
    def minDays(self, n: int) -> int:
        dp = {0:0, 1:1}
        def dfs(n):
            if n in dp:
                return dp[n]
            two = n%2+dfs(n//2)
            three = n%3+dfs(n//3)
            dp[n] = 1+min(two, three)
            return dp[n]
        return dfs(n)

39