title: Ugly Numbers
signature: pub fn ugly_numbers(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(
        27, 
        64
      ));
      
      println!("TEST-1...{}", driver(
        64, 
        450
      ));
      
      println!("TEST-2...{}", driver(
        93, 
        1250
      ));
      
      println!("TEST-3...{}", driver(
        90, 
        1152
      ));
      
      println!("TEST-4...{}", driver(
        85, 
        972
      ));
      
      println!("TEST-5...{}", driver(
        86, 
        1000
      ));
      
      println!("TEST-6...{}", driver(
        72, 
        625
      ));
      
      println!("TEST-7...{}", driver(
        86, 
        1000
      ));
      
      println!("TEST-8...{}", driver(
        32, 
        90
      ));
      
      println!("TEST-9...{}", driver(
        1, 
        1
      ));
      
  }
source_py: def ugly_numbers(n):
      ugly = ([0] * n)
      ugly[0] = 1
      i2 = i3 = i5 = 0
      next_multiple_of_2 = 2
      next_multiple_of_3 = 3
      next_multiple_of_5 = 5
      for l in range(1, n):
          ugly[l] = min(next_multiple_of_2, next_multiple_of_3, next_multiple_of_5)
          if (ugly[l] == next_multiple_of_2):
              i2 += 1
              next_multiple_of_2 = (ugly[i2] * 2)
          if (ugly[l] == next_multiple_of_3):
              i3 += 1
              next_multiple_of_3 = (ugly[i3] * 3)
          if (ugly[l] == next_multiple_of_5):
              i5 += 1
              next_multiple_of_5 = (ugly[i5] * 5)
      return ugly[(- 1)]
source_cpp: unsigned ugly_numbers(unsigned n) {
    unsigned ugly [ n ];
    unsigned i2 = 0, i3 = 0, i5 = 0;
    unsigned next_multiple_of_2 = 2;
    unsigned next_multiple_of_3 = 3;
    unsigned next_multiple_of_5 = 5;
    unsigned next_ugly_no = 1;
    ugly [ 0 ] = 1;
    for ( int i = 1;
    i < n;
    i ++ ) {
      next_ugly_no = min ( next_multiple_of_2, min ( next_multiple_of_3, next_multiple_of_5 ) );
      ugly [ i ] = next_ugly_no;
      if ( next_ugly_no == next_multiple_of_2 ) {
        i2 = i2 + 1;
        next_multiple_of_2 = ugly [ i2 ] * 2;
      }
      if ( next_ugly_no == next_multiple_of_3 ) {
        i3 = i3 + 1;
        next_multiple_of_3 = ugly [ i3 ] * 3;
      }
      if ( next_ugly_no == next_multiple_of_5 ) {
        i5 = i5 + 1;
        next_multiple_of_5 = ugly [ i5 ] * 5;
      }
    }
    return next_ugly_no;
  }