I'm trying to write a function that gets a list of numbers and variable "v", this function should return a list all subgroups of the list that sums "v" without repeating
Example: if list = [2,3,5,6,8,9,1] and v = 11 it should return [[9,2], [8,3], [5,6], [2,3,5,1], [8,2,1], [6,3,2]]
Edit: the numbers in list are positives and v number isn't going to be much bigger than the sum in list
I've tried doing splits of the list and making it doubly linked list, and then counting the subgroups, but I don't really get to the answer.
This one to go through the list and then trying to extract the items, but I don't really know how to do it
def traverse(self, head):
if (head == None):
return
current_node = head
count = 1
while (current_node):
count += 1
current_node = current_node.next
return count