title: Count Natural Numbers Whose Permutation Greater Number
signature: def countNaturalNumbersWhosePermutationGreaterNumber(n: Int) = {
test_code: import scala.collection.mutable.HashMap
  import scala.collection.immutable.HashSet
  
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  
  // TESTING CODE 
  // ============================================
  def validateSolution(actual: Int , expected: Int): Boolean = {
      actual.toString == expected.toString
  }
  
  def driver(n: Int, expected: Int): String = {
      try {
          if (validateSolution(PLACEHOLDER_FN_NAME(n),expected)) {
              "PASSED"
          } else{
              "FAILED"
          }
      }catch{
          case e: Exception => {e.getClass.getName}
      }
  
  }
  object QuestionEvaluator extends App {
  
      println(s"TEST-0...${driver(
        69, 
        48    
      )}")   
  
  
      println(s"TEST-1...${driver(
        72, 
        48    
      )}")   
  
  
      println(s"TEST-2...${driver(
        88, 
        52    
      )}")   
  
  
      println(s"TEST-3...${driver(
        7, 
        7    
      )}")   
  
  
      println(s"TEST-4...${driver(
        66, 
        45    
      )}")   
  
  
      println(s"TEST-5...${driver(
        34, 
        28    
      )}")   
  
  
      println(s"TEST-6...${driver(
        23, 
        20    
      )}")   
  
  
      println(s"TEST-7...${driver(
        37, 
        31    
      )}")   
  
  
      println(s"TEST-8...${driver(
        33, 
        27    
      )}")   
  
  
      println(s"TEST-9...${driver(
        21, 
        18    
      )}")   
  
  }
  
source_py: def count_natural_numbers_whose_permutation_greater_number(n):
      result = 0
      for i in range(1, 10):
          s = []
          if (i <= n):
              s.append(i)
              result += 1
          while (len(s) != 0):
              tp = s[(- 1)]
              s.pop()
              for j in range((tp % 10), 10):
                  x = ((tp * 10) + j)
                  if (x <= n):
                      s.append(x)
                      result += 1
      return result
source_cpp: int count_natural_numbers_whose_permutation_greater_number(int n) {
    int result = 0;
    for ( int i = 1;
    i <= 9;
    i ++ ) {
      stack < int > s;
      if ( i <= n ) {
        s . push ( i );
        result ++;
      }
      while ( ! s . empty ( ) ) {
        int tp = s . top ( );
        s . pop ( );
        for ( int j = tp % 10;
        j <= 9;
        j ++ ) {
          int x = tp * 10 + j;
          if ( x <= n ) {
            s . push ( x );
            result ++;
          }
        }
      }
    }
    return result;
  }