Very Simple Solution || Easy to understand
Complexity\n- Time complexity: O(2^n)\n\n- Space complexity: O(n)\n\n# Code\n\nclass Solution {\n    void solve(int i, vector<int>& tasks, vector<int>& session,
# Complexity\n- Time complexity: $$O(2^n)$$\n\n- Space complexity: $$O(n)$$\n\n# Code\n```\nclass Solution {\n    void solve(int i, vector<int>& tasks, vector<int>& session, int sessionTime, int &ans)\n    {\n        if(i == tasks.size()) { //base case\n         ans = min(ans,int(session.size())); //update the minimum sessions needed\n         return;\n        }\n\n        if(session.size() > ans) //early exit (VERY IMPORTANT to avoid TLE) \n           return;\n\n        //CASE 1: add tasks[i] to any of the existing session\n        for(int j=0; j<session.size(); j++) {\n            if(session[j] + tasks[i] <= sessionTime) { //only add if it\'s possible\n                session[j] += tasks[i];\n                solve(i+1,tasks,session,sessionTime,ans);\n                session[j] -= tasks[i];\n            }\n        }\n        //CASE 2: add tasks[i] to a new session\n        session.push_back(tasks[i]);\n        solve(i+1,tasks,session,sessionTime,ans);\n        session.pop_back();\n    }\npublic:\n    int minSessions(vector<int>& tasks, int sessionTime) {\n        int ans = INT_MAX;\n        vector<int> session;\n        solve(0,tasks,session,sessionTime,ans);\n        return ans;\n    }\n};\n```
['Backtracking', 'C++']