title: Minimum Sum Two Numbers Formed Digits Array 2
signature: long long minimumSumTwoNumbersFormedDigitsArray2(vector<int> a, int n) {
test_code: #include <algorithm>
  #include <assert.h>
  #include <cstdlib>
  #include <iostream>
  #include <map>
  #include <set>
  #include <string>
  #include <tuple> 
  #include <unordered_map>
  #include <vector>
  #include <math.h>
  #include <cmath>
  #include <bits/stdc++.h>
  #include <numeric>
  #include <functional>
  
  using namespace std;
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  bool validateSolution(long long actual, long long expected){
      return actual == expected;
  }
  
  string driver(vector<int> a, int n, long long expected){
      try
      {
          if (validateSolution(PLACEHOLDER_FN_NAME(a, n), expected)){
              return "PASSED";
          }
          return "FAILED";
      }
      catch (const std::overflow_error& exception_obj)
      {
          return typeid(exception_obj).name();
      }
      catch (const std::runtime_error& exception_obj)
      {
          return typeid(exception_obj).name();
      }
      catch (const std::exception& exception_obj)
      {
          return typeid(exception_obj).name();
      }
      catch (...)
      {
          return "UNK_ERROR";
      }
  }
  
  int main() {
      string result = "";
  
      result = driver({4, 16, 29, 30, 38, 83}, 5, 918); 
      cout << "TEST-" << 0 << "..."
           <<  result
           << "\n";
  
      result = driver({58, 74, -28, -60, -6, 66, -76, 46, 0, -24, 28, -16, -14, 24, -94, -56, -80, 40, -18, -68, -8, -94, -88, -12, -20, -8}, 16, -2063616120); 
      cout << "TEST-" << 1 << "..."
           <<  result
           << "\n";
  
      result = driver({0, 1}, 1, 0); 
      cout << "TEST-" << 2 << "..."
           <<  result
           << "\n";
  
      result = driver({7, 12, 78, 8}, 3, 90); 
      cout << "TEST-" << 3 << "..."
           <<  result
           << "\n";
  
      result = driver({-78, -48, -48, -26, 8, 34}, 4, -1334); 
      cout << "TEST-" << 4 << "..."
           <<  result
           << "\n";
  
      result = driver({1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0}, 27, 2222222); 
      cout << "TEST-" << 5 << "..."
           <<  result
           << "\n";
  
      result = driver({2, 3, 5, 7, 25, 30, 31, 38, 42, 45, 52, 53, 56, 59, 60, 71, 74, 76, 80, 90, 91, 98}, 13, 3190079); 
      cout << "TEST-" << 6 << "..."
           <<  result
           << "\n";
  
      result = driver({0, 0, 0, 0, 0, 0, 1, 1, 1}, 8, 2); 
      cout << "TEST-" << 7 << "..."
           <<  result
           << "\n";
  
      result = driver({59, 9, 3, 20, 83, 87, 48, 4, 86, 67, 89, 96, 17, 36, 39, 45, 99, 8, 56, 92, 63, 81, 7, 75, 32, 10, 71, 82, 97, 92, 65, 23, 22, 47, 70, 79, 57, 81, 65, 50}, 35, 430183530665338166); 
      cout << "TEST-" << 8 << "..."
           <<  result
           << "\n";
  
      return 0;
  }
source_py: def minimum_sum_two_numbers_formed_digits_array_2(a, n):
      a = sorted(a)
      (num1, num2) = (0, 0)
      for i in range(n):
          if ((i % 2) == 0):
              num1 = ((num1 * 10) + a[i])
          else:
              num2 = ((num2 * 10) + a[i])
      return (num2 + num1)
source_cpp: int minimum_sum_two_numbers_formed_digits_array_2(vector<int> a, int n) {
    sort(a.begin(), a.end());
    int num1 = 0;
    int num2 = 0;
    for ( int i = 0;
    i < n;
    i ++ ) {
      if ( i % 2 == 0 ) num1 = num1 * 10 + a [ i ];
      else num2 = num2 * 10 + a [ i ];
    }
    return num2 + num1;
  }