Minimum steps to reduce N to 0 by given operations | Function to find the minimum number to steps to reduce N to 0 ; Dictionary for storing the precomputed sum ; Bases Cases ; Check if n is not in dp then only call the function so as to reduce no of recursive calls ; Return the answer ; Given Number N ; Function Call
def count ( n ) : NEW_LINE INDENT dp = dict ( ) NEW_LINE dp [ 0 ] = 0 NEW_LINE dp [ 1 ] = 1 NEW_LINE if n not in dp : NEW_LINE INDENT dp [ n ] = 1 + min ( n % 2 + count ( n // 2 ) , n % 3 + count ( n // 3 ) ) NEW_LINE DEDENT return dp [ n ] NEW_LINE DEDENT N = 6 NEW_LINE print ( str ( count ( N ) ) ) NEW_LINE