If it is a valid move then update the minimum steps required
if ( i + k < n && str [ i + k ] == ' ' ) steps = Math . min ( steps , dp [ i + k ] ) ; if ( str [ i + 1 ] == ' ' ) steps = Math . min ( steps , dp [ i + 1 ] ) ; if ( str [ i + 2 ] == ' ' ) steps = Math . min ( steps , dp [ i + 2 ] ) ;