static int countSteps ( int [ ] val , int n ) {
  int sol = 0 ;
  Vector < Integer > vec = new Vector < > ( 1 ) ;
  vec . add ( 0 ) ;
  status [ 0 ] = - 1 ;
  for ( int i = 1 ;
  i < n ;
  ++ i ) {
    status [ i ] = 0 ;
    while ( vec . size ( ) > 0 && val [ vec . lastElement ( ) ] >= val [ i ] ) {
      status [ i ] = Math . max ( status [ i ] , status [ vec . lastElement ( ) ] + 1 ) ;
      vec . remove ( vec . lastElement ( ) ) ;
    }
    if ( vec . isEmpty ( ) ) {
      status [ i ] = - 1 ;
    }
    vec . add ( i ) ;
    sol = Math . max ( sol , status [ i ] + 1 ) ;
  }
  return sol ;
}

static int countSteps ( int [ ] val , int n ) { int sol = 0 ; Vector < Integer > vec = new Vector < > ( 1 ) ; vec . add ( 0 ) ; status [ 0 ] = - 1 ; for ( int i = 1 ; i < n ; ++ i ) { status [ i ] = 0 ; while ( vec . size ( ) > 0 && val [ vec . lastElement ( ) ] >= val [ i ] ) { status [ i ] = Math . max ( status [ i ] , status [ vec . lastElement ( ) ] + 1 ) ; vec . remove ( vec . lastElement ( ) ) ; } if ( vec . isEmpty ( ) ) { status [ i ] = - 1 ; } vec . add ( i ) ; sol = Math . max ( sol , status [ i ] + 1 ) ; } return sol ; }
(method_declaration (modifiers) type: (integral_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (integral_type) dimensions: (dimensions)) name: (identifier)) (formal_parameter type: (integral_type) name: (identifier))) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (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 (decimal_integer_literal))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (decimal_integer_literal)))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (decimal_integer_literal)) right: (unary_expression operand: (decimal_integer_literal)))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (block (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (decimal_integer_literal))) (while_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) right: (decimal_integer_literal)) right: (binary_expression left: (array_access array: (identifier) index: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) right: (array_access array: (identifier) index: (identifier))))) body: (block (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (identifier)) (binary_expression left: (array_access array: (identifier) index: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) right: (decimal_integer_literal)))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))))))) (if_statement condition: (parenthesized_expression (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) consequence: (block (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (unary_expression operand: (decimal_integer_literal)))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))) (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (decimal_integer_literal)))))))) (return_statement (identifier))))