title: Count Natural Numbers Whose Permutation Greater Number
signature: countNaturalNumbersWhosePermutationGreaterNumber(n) {
test_code: import 'dart:convert';
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  bool validateSolution(int actual, int expected){
      return actual.toString() == expected.toString();
  }
  
  String driver(n, int expected){
      try
      {
          if (validateSolution(PLACEHOLDER_FN_NAME(n), expected)){
              return "PASSED";
          }
          return "FAILED";
      }catch(exception_object){
          return exception_object.runtimeType.toString();
      }
  }
  
  int main() {
  
      print("TEST-0...${driver(
          69, 
          48)
      }");
  
      print("TEST-1...${driver(
          72, 
          48)
      }");
  
      print("TEST-2...${driver(
          88, 
          52)
      }");
  
      print("TEST-3...${driver(
          7, 
          7)
      }");
  
      print("TEST-4...${driver(
          66, 
          45)
      }");
  
      print("TEST-5...${driver(
          34, 
          28)
      }");
  
      print("TEST-6...${driver(
          23, 
          20)
      }");
  
      print("TEST-7...${driver(
          37, 
          31)
      }");
  
      print("TEST-8...${driver(
          33, 
          27)
      }");
  
      print("TEST-9...${driver(
          21, 
          18)
      }");
  
      return 0;
  }
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;
  }