title: Subset Sum Divisible M
signature: bool subsetSumDivisibleM(vector<int> arr, int n, int m) {
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(bool actual, bool expected){
      return actual == expected;
  }
  
  string driver(vector<int> arr, int n, int m, bool expected){
      try
      {
          if (validateSolution(PLACEHOLDER_FN_NAME(arr, n, m), 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({2, 5, 7, 12, 13, 13, 15, 18, 20, 21, 22, 26, 27, 41, 41, 50, 53, 57, 58, 58, 61, 62, 62, 64, 70, 75, 78, 79, 81, 81, 81, 83, 86, 91, 93, 95, 97, 99, 99}, 36, 35, true); 
      cout << "TEST-" << 0 << "..."
           <<  result
           << "\n";
  
      result = driver({8, 16, 62, -24, 14, -4, 2, 50, -64, -76, 78, 66, -64, 18}, 12, 11, true); 
      cout << "TEST-" << 1 << "..."
           <<  result
           << "\n";
  
      result = driver({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, 1, 1, 1, 1, 1, 1}, 32, 27, true); 
      cout << "TEST-" << 2 << "..."
           <<  result
           << "\n";
  
      result = driver({50, 20, 79, 42, 85, 24, 20, 76, 36, 88, 40, 5, 24, 85, 7, 19, 43, 51, 94, 13, 53, 93, 92, 43, 97, 38, 80, 48, 52, 47, 77, 56, 41, 80, 32, 34, 77, 14, 70, 3}, 29, 27, true); 
      cout << "TEST-" << 3 << "..."
           <<  result
           << "\n";
  
      result = driver({-96, -94, -72, -58, -48, -36, -28, -26, -10, -10, -8, -8, -6, 2, 14, 30, 30, 54, 58, 60, 64, 68, 78, 84, 96, 98}, 16, 18, true); 
      cout << "TEST-" << 4 << "..."
           <<  result
           << "\n";
  
      result = driver({1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0}, 7, 8, true); 
      cout << "TEST-" << 5 << "..."
           <<  result
           << "\n";
  
      result = driver({2, 7, 8, 15, 18, 23, 24, 25, 27, 35, 40, 42, 43, 46, 48, 50, 53, 64, 66, 69, 70, 71, 72, 77, 78, 80, 81, 81, 81, 82, 82, 82, 84, 87, 97, 98}, 23, 32, true); 
      cout << "TEST-" << 6 << "..."
           <<  result
           << "\n";
  
      result = driver({46, 54, 24, -10}, 3, 3, true); 
      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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 21, 34, true); 
      cout << "TEST-" << 8 << "..."
           <<  result
           << "\n";
  
      result = driver({39, 21, 38, 6, 38, 44, 96, 1, 16, 1, 28, 4, 55, 8}, 12, 11, true); 
      cout << "TEST-" << 9 << "..."
           <<  result
           << "\n";
  
      return 0;
  }
source_py: def subset_sum_divisible_m(arr, n, m):
      if (n > m):
          return True
      DP = [False for i in range(m)]
      for i in range(n):
          if DP[0]:
              return True
          temp = [False for i in range(m)]
          for j in range(m):
              if (DP[j] == True):
                  if (DP[((j + arr[i]) % m)] == False):
                      temp[((j + arr[i]) % m)] = True
          for j in range(m):
              if temp[j]:
                  DP[j] = True
          DP[(arr[i] % m)] = True
      return DP[0]
source_cpp: bool subset_sum_divisible_m(vector<int> arr, int n, int m) {
    if ( n > m ) return true;
    bool DP [ m ];
    memset ( DP, false, m );
    for ( int i = 0;
    i < n;
    i ++ ) {
      if ( DP [ 0 ] ) return true;
      bool temp [ m ];
      memset ( temp, false, m );
      for ( int j = 0;
      j < m;
      j ++ ) {
        if ( DP [ j ] == true ) {
          if ( DP [ ( j + arr [ i ] ) % m ] == false ) temp [ ( j + arr [ i ] ) % m ] = true;
        }
      }
      for ( int j = 0;
      j < m;
      j ++ ) if ( temp [ j ] ) DP [ j ] = true;
      DP [ arr [ i ] % m ] = true;
    }
    return DP [ 0 ];
  }