allPossibleSolutions = [] def helper(arr, spotsTaken, ind): if ind == len(arr): return for j in range(arr[ind][0], arr[ind][1]+1): if j not in spotsTaken: allPossibleSolutions.append(spotsTaken+[j]) helper(arr, spotsTaken+[j], ind+1) def max_meetings(times): helper(times, [], 0) myMax = 0 for sol in allPossibleSolutions: if len(sol) > myMax: myMax = len(sol) return myMax ret = max_meetings([[2, 2], [4, 5], [4, 10], [5, 6], [5, 7], [6, 6]])