title: Find Smallest Value Represented Sum Subset Given Array
signature: int findSmallestValueRepresentedSumSubsetGivenArray(vector<int> arr, 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(int actual, int expected){
      return actual == expected;
  }
  
  string driver(vector<int> arr, int n, int expected){
      try
      {
          if (validateSolution(PLACEHOLDER_FN_NAME(arr, 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({16, 23, 24, 41, 48, 58, 72, 75}, 4, 1); 
      cout << "TEST-" << 0 << "..."
           <<  result
           << "\n";
  
      result = driver({-14, -82, 12, -14, -38, 12, 40, 12, -74, 42, -36, 64}, 8, -95); 
      cout << "TEST-" << 1 << "..."
           <<  result
           << "\n";
  
      result = driver({0, 0, 1, 1, 1, 1}, 5, 4); 
      cout << "TEST-" << 2 << "..."
           <<  result
           << "\n";
  
      result = driver({17, 89, 44}, 2, 1); 
      cout << "TEST-" << 3 << "..."
           <<  result
           << "\n";
  
      result = driver({-94, -92, -84, -82, -72, -58, -56, -40, -34, -34, -24, -22, -8, -8, 12, 14, 16, 16, 22, 22, 34, 46, 54, 58, 68, 72, 74, 78, 88, 96}, 25, -93); 
      cout << "TEST-" << 4 << "..."
           <<  result
           << "\n";
  
      result = driver({0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0}, 8, 2); 
      cout << "TEST-" << 5 << "..."
           <<  result
           << "\n";
  
      result = driver({2, 12, 13, 13, 13, 16, 28, 32, 34, 41, 41, 47, 49, 49, 50, 52, 58, 61, 63, 65, 67, 68, 68, 74, 80, 80, 84, 84, 89, 93, 94, 98, 99, 99}, 23, 1); 
      cout << "TEST-" << 6 << "..."
           <<  result
           << "\n";
  
      result = driver({-54}, 0, 1); 
      cout << "TEST-" << 7 << "..."
           <<  result
           << "\n";
  
      result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 33, 12); 
      cout << "TEST-" << 8 << "..."
           <<  result
           << "\n";
  
      result = driver({42, 50, 76, 45, 6, 63, 46, 73, 65, 70, 87, 5, 41, 63, 96, 75, 38, 76, 27, 7, 71, 9, 65, 44, 76, 37, 94, 52, 55, 3, 38, 68, 45, 15, 35, 90, 36, 46, 13, 92, 32, 22, 49, 35, 83}, 35, 1); 
      cout << "TEST-" << 9 << "..."
           <<  result
           << "\n";
  
      return 0;
  }
source_py: def find_smallest_value_represented_sum_subset_given_array(arr, n):
      res = 1
      for i in range(0, n):
          if (arr[i] <= res):
              res = (res + arr[i])
          else:
              break
      return res
source_cpp: int find_smallest_value_represented_sum_subset_given_array(vector<int> arr, int n) {
    int res = 1;
    for ( int i = 0;
    i < n && arr [ i ] <= res;
    i ++ ) res = res + arr [ i ];
    return res;
  }