public static int findMoves ( int n , int m ) {
  Set < Integer > visited = new HashSet < > ( ) ;
  Queue < Integer > nodes = new LinkedList < > ( ) ;
  nodes . add ( n ) ;
  int moves = 0 ;
  while ( ! nodes . isEmpty ( ) ) {
    if ( nodes . contains ( m ) ) {
      break ;
    }
    Queue < Integer > children = new LinkedList < > ( ) ;
    while ( ! nodes . isEmpty ( ) ) {
      Integer num = nodes . poll ( ) ;
      if ( ! visited . contains ( num ) ) {
        visited . add ( num ) ;
        children . add ( num * 2 ) ;
        children . add ( num - 1 ) ;
      }
    }
    nodes = children ;
    moves ++ ;
  }
  return moves ;
}

public static int findMoves ( int n , int m ) { Set < Integer > visited = new HashSet < > ( ) ; Queue < Integer > nodes = new LinkedList < > ( ) ; nodes . add ( n ) ; int moves = 0 ; while ( ! nodes . isEmpty ( ) ) { if ( nodes . contains ( m ) ) { break ; } Queue < Integer > children = new LinkedList < > ( ) ; while ( ! nodes . isEmpty ( ) ) { Integer num = nodes . poll ( ) ; if ( ! visited . contains ( num ) ) { visited . add ( num ) ; children . add ( num * 2 ) ; children . add ( num - 1 ) ; } } nodes = children ; moves ++ ; } return moves ; }
(method_declaration (modifiers) type: (integral_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (integral_type) name: (identifier)) (formal_parameter type: (integral_type) name: (identifier))) body: (block (local_variable_declaration type: (generic_type (type_identifier) (type_arguments (type_identifier))) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (generic_type (type_identifier) (type_arguments)) arguments: (argument_list)))) (local_variable_declaration type: (generic_type (type_identifier) (type_arguments (type_identifier))) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (generic_type (type_identifier) (type_arguments)) arguments: (argument_list)))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (while_statement condition: (parenthesized_expression (unary_expression operand: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) body: (block (if_statement condition: (parenthesized_expression (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))) consequence: (block (break_statement))) (local_variable_declaration type: (generic_type (type_identifier) (type_arguments (type_identifier))) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (generic_type (type_identifier) (type_arguments)) arguments: (argument_list)))) (while_statement condition: (parenthesized_expression (unary_expression operand: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) body: (block (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (if_statement condition: (parenthesized_expression (unary_expression operand: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))))) consequence: (block (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (identifier) right: (decimal_integer_literal))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (identifier) right: (decimal_integer_literal))))))))) (expression_statement (assignment_expression left: (identifier) right: (identifier))) (expression_statement (update_expression (identifier))))) (return_statement (identifier))))