Path traversed using exactly M coins in K jumps | Function that pr the path using exactly K jumps and M coins ; If no path exists ; It decides which box to be jump ; It decides whether to jump on left side or to jump on right side ; Print the path ; Driver code ; Function call
def print_path ( N , jump , coin ) : NEW_LINE INDENT if ( jump > coin or jump * ( N - 1 ) < coin ) : NEW_LINE INDENT print ( " - 1" ) NEW_LINE DEDENT else : NEW_LINE INDENT pos = 1 ; NEW_LINE while ( jump > 0 ) : NEW_LINE INDENT tmp = min ( N - 1 , coin - ( jump - 1 ) ) ; NEW_LINE if ( pos + tmp <= N ) : NEW_LINE INDENT pos += tmp ; NEW_LINE DEDENT else : NEW_LINE INDENT pos -= tmp ; NEW_LINE DEDENT print ( pos , end = " ▁ " ) NEW_LINE coin -= tmp ; NEW_LINE jump -= 1 ; NEW_LINE DEDENT DEDENT DEDENT N = 5 NEW_LINE K = 4 NEW_LINE M = 12 NEW_LINE print_path ( N , K , M ) ; NEW_LINE