<gouthampradhan>depth_first_search_CrackingTheSafe_2.java
private String dfs(
      String num, StringBuilder result, Set<String> done, int k, int states, int count) {
    done.add(num);
    if (states == count) {
      return result.toString();
    } else {
      for (int i = 0; i < k; i++) {
        String newNum = (num + String.valueOf(i));
        String newState = newNum.substring(1);
        if (!done.contains(newState)) {
          String retValue =
              dfs(newState, result.append(String.valueOf(i)), done, k, states, count + 1);
          if (!retValue.isEmpty()) {
            return retValue;
          } else {
            result.deleteCharAt(result.length() - 1);
          }
        }
      }
    }
    done.remove(num);
    return "";
  }
private String sample_funcname ( String num , StringBuilder result , Set < String > done , int k , int states , int count ) {
  done . add ( num ) ;
  if ( states == count ) {
    return result . toString ( ) ;
  }
  else {
    for ( int i = 0 ;
    i < k ;
    i ++ ) {
      String newNum = ( num + String . valueOf ( i ) ) ;
      String newState = newNum . substring ( 1 ) ;
      if ( ! done . contains ( newState ) ) {
        String retValue = dfs ( newState , result . append ( String . valueOf ( i ) ) , done , k , states , count + 1 ) ;
        if ( ! retValue . isEmpty ( ) ) {
          return retValue ;
        }
        else {
          result . deleteCharAt ( result . length ( ) - 1 ) ;
        }
      }
    }
  }
  done . remove ( num ) ;
  return "" ;
}
