If we consider l as -1 and r as +1 , it is equivalent to finding distinct subset/subsequence with a given sum. Is there any optimal way to calculate that.