title: Ugly Numbers
signature: function uglyNumbers(n: number): number {
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;
  }
question_info.test_list: [{"idx": 0, "outputs": 64, "inputs": {"n": 27}}, {"idx": 1, "outputs": 450, "inputs": {"n": 64}}, {"idx": 2, "outputs": 1250, "inputs": {"n": 93}}, {"idx": 3, "outputs": 1152, "inputs": {"n": 90}}, {"idx": 4, "outputs": 972, "inputs": {"n": 85}}, {"idx": 5, "outputs": 1000, "inputs": {"n": 86}}, {"idx": 6, "outputs": 625, "inputs": {"n": 72}}, {"idx": 7, "outputs": 1000, "inputs": {"n": 86}}, {"idx": 8, "outputs": 90, "inputs": {"n": 32}}, {"idx": 9, "outputs": 1, "inputs": {"n": 1}}]
question_info.entry_cls_name: Solution
question_info.test_code: 
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  function convertToString(value: any): string{
      return JSON.stringify(value, function (key, val) {
          if (val instanceof Set) {
              return Array.from(val);
          } return val;});
  }
  
  function validateSolution(actual: number, expected: number): boolean {
      return convertToString(actual) === convertToString(expected);
  }
  
  function driver(n: number, expected:number): string {
      try{
          if (validateSolution(PLACEHOLDER_FN_NAME(n),expected)){
              return "PASSED";
          }
          return "FAILED";
      } catch (error) {
        return error.name;
      }
      
  }
      
  function main(){
    let result = '';
    result = driver(27, 64);
    console.log(`TEST-0...${result}`);
  
    result = driver(64, 450);
    console.log(`TEST-1...${result}`);
  
    result = driver(93, 1250);
    console.log(`TEST-2...${result}`);
  
    result = driver(90, 1152);
    console.log(`TEST-3...${result}`);
  
    result = driver(85, 972);
    console.log(`TEST-4...${result}`);
  
    result = driver(86, 1000);
    console.log(`TEST-5...${result}`);
  
    result = driver(72, 625);
    console.log(`TEST-6...${result}`);
  
    result = driver(86, 1000);
    console.log(`TEST-7...${result}`);
  
    result = driver(32, 90);
    console.log(`TEST-8...${result}`);
  
    result = driver(1, 1);
    console.log(`TEST-9...${result}`);
  
  };
  
  main();
question_info.extension: ts
question_info.entry_fn_name: uglyNumbers
question_info.test_case_ids: 0 1 2 3 4 5 6 7 8 9
question_info.commands: tsc --target es2020 --lib es5,dom,es2015,es2020 __FILENAME__
question_info.commands: node __FILENAME__.js