title: Return elements of array in subset sum problem
body: <p>For the following recursive solution to the subset sum problem (<a href="https://www.geeksforgeeks.org/subset-sum-problem-dp-25/" rel="nofollow noreferrer">see this link</a>), the following code returns true if there is any subset in <code>a</code> whose sum equals the value of <code>sum</code> </p>
  
  <pre><code>def isSubsetSum(set,n, sum) : 
  
      # Base Cases 
      if (sum == 0) : 
          return True
      if (n == 0 and sum != 0) : 
          return False
  
      # If last element is greater than sum, then ignore it 
      if (set[n - 1] &gt; sum) : 
          return isSubsetSum(set, n - 1, sum); 
  
      # else, check if sum can be obtained by any of the following 
      # (a) including the last element 
      # (b) excluding the last element    
      return isSubsetSum(set, n-1, sum) or isSubsetSum(set, n-1, sum-set[n-1]) 
  
  set = [2, 1, 14, 12, 15, 2] 
  sum = 9
  n = len(set) 
  if (isSubsetSum(set, n, sum) == True) : 
      print("Found a subset with given sum") 
  else : 
      print("No subset with given sum") 
  </code></pre>
  
  <p>How could I also return the indices of <code>a</code> which satisfy the <code>sum</code>?</p>
  
  <p>Also, how can I make the function work for negative integers in array <code>a</code>.</p>