If the state has already been computed
if ( dp [ digit ] [ prev1 ] [ prev2 ] != - 1 ) : NEW_LINE INDENT return dp [ digit ] [ prev1 ] [ prev2 ] NEW_LINE DEDENT dp [ digit ] [ prev1 ] [ prev2 ] = 0 NEW_LINE