Binary Search & Backtracking | 100%
IntuitionSince the goal is to minimize work sessions lets binary search the number of sessions possible. So a basic binary search with the conditional being can
# Intuition
Since the goal is to minimize work sessions lets binary search the number of sessions possible. So a basic binary search with the conditional being `canPartition`, where `canPartition` simply tries to fit all tasks into `mid` number of work sessions.

# Complexity
- Time complexity:
O( logn * k^n )

- Space complexity:
O(n)

# Code
```cpp []
class Solution {
public:
    int minSessions(vector<int>& tasks, int sessionTime) {
        sort(tasks.rbegin(), tasks.rend());
        int left = 1, right = tasks.size();

        while (left < right) {
            int mid = (left + right) / 2;
            vector<int> sessions(mid, 0);
            if (canPartition(tasks, sessions, 0, sessionTime)) {
                right = mid;
            } else {
                left = mid + 1;
            }
        }
        return left;
    }
    
    bool canPartition(vector<int>& tasks, vector<int>& sessions, int index, int sessionTime) {
        if (index == tasks.size()) return true;
        unordered_set<int> seen;

        for (int& session : sessions) {
            if (seen.count(session)) continue;
            if (session + tasks[index] <= sessionTime) {
                session += tasks[index];
                if (canPartition(tasks, sessions, index + 1, sessionTime)) return true;
                session -= tasks[index];
                
                seen.insert(session);
                if (session == 0) break;
            }
        }

        return false;
    }
};

```
['Binary Search', 'Backtracking', 'C++']