got it!

so I ended up going with recursion… if we have a larger input set, a
little bit of branch pruning will be essential, but it’s not needed for
this problem