This article tells all possible subset sum for an array. Here is the link - https://www.geeksforgeeks.org/subset-sum-queries-using-bitset/ Although in that link there was no good explanation why this approach works.