<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>

class Solution:

    # recursion with memoization
    def noOfDays(self, oranges, memo):
        if oranges in memo:
            return memo[oranges]

        if oranges == 0:
            return 0

        if oranges == 1:
            return 1

        daysForTwo = inf
        daysForThree = inf
        daysForOne = inf

        daysForOne = self.noOfDays(oranges - 1, memo)

        if oranges % 2 == 0:
            daysForTwo = self.noOfDays(oranges // 2, memo)

        if oranges % 3 == 0:
            daysForThree = self.noOfDays(oranges // 3, memo)
        

        ans =  1 + min(daysForTwo, daysForThree, daysForOne)

        memo[oranges] = ans
        return ans

    def calculate(self, n):
        dp = [0 for _ in range(n+1)]
        dp[1] = 1

        for i in range(2, n+1):
            minSteps = dp[i-1]
            if i % 2 == 0:
                minSteps = min(minSteps, dp[i // 2])
            if i % 3 == 0:
                minSteps = min(minSteps, dp[i // 3])
        
            dp[i] = 1 + minSteps
        return dp[n]

    def ans(self, n):
        @lru_cache(None)
        def fn(n):
            if n <= 1: return n
            return 1 + min(n%2 + fn(n//2), n%3 + fn(n//3))
        
        return fn(n)


    def minDays(self, n: int) -> int:
        return self.ans(n)

        
17200