title: Count Natural Numbers Whose Permutation Greater Number
signature: pub fn count_natural_numbers_whose_permutation_greater_number(n: i32) -> i32 {
test_code: use std::collections::HashMap;
  use std::collections::HashSet;
  use std::cmp::*;
  use std::collections::*;
  use std::fmt::*; 
  
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  pub fn validate_solution(actual: i32, expected: i32)->bool{
  return actual==expected
  }
  pub fn driver(n: i32, expected: i32)->String{
      if validate_solution(PLACEHOLDER_FN_NAME(n), expected) {
        return "PASSED".to_string();
      };
      return "FAILED".to_string();
  
  }
  
  fn main() {
      println!("TEST-0...{}", driver(
        69, 
        48
      ));
      
      println!("TEST-1...{}", driver(
        72, 
        48
      ));
      
      println!("TEST-2...{}", driver(
        88, 
        52
      ));
      
      println!("TEST-3...{}", driver(
        7, 
        7
      ));
      
      println!("TEST-4...{}", driver(
        66, 
        45
      ));
      
      println!("TEST-5...{}", driver(
        34, 
        28
      ));
      
      println!("TEST-6...{}", driver(
        23, 
        20
      ));
      
      println!("TEST-7...{}", driver(
        37, 
        31
      ));
      
      println!("TEST-8...{}", driver(
        33, 
        27
      ));
      
      println!("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;
  }