title: Subset Sum Divisible M
signature: subset_sum_divisible_m <- function(arr, n, m) {
test_code: 
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  validate_solution <- function(actual, expected) {
      toString(actual)==toString(expected)
  }
  
  driver <- function(arr, n, m, expected){
      if (validate_solution(PLACEHOLDER_FN_NAME(arr, n, m), expected)){
          "PASSED"
      } else{
          "FAILED"
      }
  }
  
  main <- function() {
      cat(sprintf("TEST-0...%s\n",driver(
          list(2L, 5L, 7L, 12L, 13L, 13L, 15L, 18L, 20L, 21L, 22L, 26L, 27L, 41L, 41L, 50L, 53L, 57L, 58L, 58L, 61L, 62L, 62L, 64L, 70L, 75L, 78L, 79L, 81L, 81L, 81L, 83L, 86L, 91L, 93L, 95L, 97L, 99L, 99L), 36L, 35L, 
          TRUE
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          list(8L, 16L, 62L, -24L, 14L, -4L, 2L, 50L, -64L, -76L, 78L, 66L, -64L, 18L), 12L, 11L, 
          TRUE
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 32L, 27L, 
          TRUE
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          list(50L, 20L, 79L, 42L, 85L, 24L, 20L, 76L, 36L, 88L, 40L, 5L, 24L, 85L, 7L, 19L, 43L, 51L, 94L, 13L, 53L, 93L, 92L, 43L, 97L, 38L, 80L, 48L, 52L, 47L, 77L, 56L, 41L, 80L, 32L, 34L, 77L, 14L, 70L, 3L), 29L, 27L, 
          TRUE
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          list(-96L, -94L, -72L, -58L, -48L, -36L, -28L, -26L, -10L, -10L, -8L, -8L, -6L, 2L, 14L, 30L, 30L, 54L, 58L, 60L, 64L, 68L, 78L, 84L, 96L, 98L), 16L, 18L, 
          TRUE
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          list(1L, 0L, 1L, 1L, 0L, 0L, 1L, 1L, 1L, 0L, 0L), 7L, 8L, 
          TRUE
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          list(2L, 7L, 8L, 15L, 18L, 23L, 24L, 25L, 27L, 35L, 40L, 42L, 43L, 46L, 48L, 50L, 53L, 64L, 66L, 69L, 70L, 71L, 72L, 77L, 78L, 80L, 81L, 81L, 81L, 82L, 82L, 82L, 84L, 87L, 97L, 98L), 23L, 32L, 
          TRUE
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          list(46L, 54L, 24L, -10L), 3L, 3L, 
          TRUE
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 21L, 34L, 
          TRUE
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          list(39L, 21L, 38L, 6L, 38L, 44L, 96L, 1L, 16L, 1L, 28L, 4L, 55L, 8L), 12L, 11L, 
          TRUE
      )))
  
  }
  
  main()
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 ];
  }