Easier than top voted ones | LegitClickbait | c++
Algorithm\n1. We use 2 things -> mask to denote which elements are processed. If ith bit is 1 means ith element is processed. -> currentTime we start with 0 as 
**Algorithm**\n1. We use 2 things -> ```mask``` to denote which elements are processed. If ```ith``` bit is 1 means ```ith``` element is processed. -> ```currentTime``` we start with 0 as current time.\n2. At each call go through all the unprocessed elements only.\n3. We can choose to include the ith unprocessed element in current session like this -> ```help(a, mask | (1<<i), currTime + a[i])```\n4.  Or choose to include it in next session like this -> ```1 + help(a, mask | (1<<i), a[i])```\n5.  Take minimum of step 3 and 4 across all unprocessed elements like this -> ```ans = min({ans, includeInCurrentSession, includeInNextSession})``` .\n2. If ```currentTime``` becomes more than targetTime it is invalid state.\n3. If all elements are processed then its the end of our algorithm.\n\n***Note***: \nWhen we do ```mask | (1<<i)``` we set the ith bit in mask to indicate element at ith position is processed.\nWhen we do ```mask & (1<<i)``` we are checking if ith bit in mask is set or not.\n\n**Code**\n```\nclass Solution {\npublic:\n    int n, time, allOnes;\n    int ans;\n    int dp[1<<15][16];\n    int minSessions(vector<int>& a, int t) {\n        time = t;\n        n = a.size();\n        allOnes = (1<<n)-1;\n        memset(dp, -1, sizeof dp);\n        ans = help(a, 0, 0);\n        return ans;\n    }\n    \n    int help(vector<int> &a, int mask, int currTime){\n        if(currTime > time) return INT_MAX;\n        if(mask == allOnes) return 1;\n        if(dp[mask][currTime] != -1) return dp[mask][currTime];\n        int ans = INT_MAX;\n        for(int i = 0 ; i < n ; i++){\n            if( (mask & (1<<i)) == 0){\n                int includeInCurrentSession = help(a, mask | (1<<i), currTime + a[i]);\n                int includeInNextSession = 1 + help(a, mask | (1<<i), a[i]);\n                ans = min({ans, includeInCurrentSession, includeInNextSession});\n            }\n        }\n        return dp[mask][currTime] = ans;\n    }\n};\n```\n**Time Complexity**: ```O(2^N * sessionTime * N)``` Here N is length of array ```a i.e tasks``` and sessionTime  is ```time```
['Dynamic Programming', 'Bit Manipulation', 'C']