Python | Backtracking | 664ms | 100% time and space | Explanation
I think the test cases are little weak, because I just did backtracking and a little pruning and seems to be 4x faster than bitmask solutions.\n The question bo
* I think the test cases are little weak, because I just did backtracking and a little pruning and seems to be 4x faster than bitmask solutions.\n* The question boils down to finding minimum number of subsets such that each subset sum <= sessionTime. I maintain a list called subsets, where I track each subset sum. For each tasks[i] try to fit it into one of the existing subsets or create a new subset with this tasks[i] and recurse further. Once I reach the end of the list, I compare the length of the subsets list with current best and record minimum.\n* For pruning, I do the following - Once the length of subsets is larger than current best length, I backtrack. This doesn\'t decrease complexity in mathematical terms but I think in implementation, it helps a lot.\n\n```\nclass Solution:\n    def minSessions(self, tasks: List[int], sessionTime: int) -> int:\n        subsets = []\n        self.ans = len(tasks)\n        \n        def func(idx):\n            if len(subsets) >= self.ans:\n                return\n            \n            if idx == len(tasks):\n                self.ans = min(self.ans, len(subsets))\n                return\n            \n            for i in range(len(subsets)):\n                if subsets[i] + tasks[idx] <= sessionTime:\n                    subsets[i] += tasks[idx]\n                    func(idx + 1)\n                    subsets[i] -= tasks[idx]\n            \n            subsets.append(tasks[idx])\n            func(idx + 1)\n            subsets.pop()\n        \n        func(0)\n        return self.ans
['Backtracking', 'Python3']