C++ solution | Faster than 100% of C++ soltutions | No complex Algo | Easy to understand
Explanation:\nCreate an array state of size of sessionTime initialized as 1 for all the values in tasks and 0 elsewhere. Loop it out, trying to push as many tas
**Explanation:**\nCreate an array `state` of size of `sessionTime` initialized as 1 for all the values in `tasks` and 0 elsewhere. Loop it out, trying to push as many `tasks` as possible with sum not more than `sessionTime`, else break. Decrement all the values of  `state` array that get executed to avoid repetitions. \n\n**Code:**\n\n```\nclass Solution {\npublic:\n    int minSessions(vector<int>& tasks, int sessionTime) {\n        if(tasks.size() == 1) return 1;\n        int ans = 0;\n        vector<int> state(15, 0);\n        for(int i=0; i<tasks.size(); i++) {\n            state[tasks[i]]++;\n        }\n        int i = 14;\n        while(i > 0) {\n            if(state[i] > 0) {\n                int curr = i;\n                int diff = sessionTime - curr;\n                state[i]--;\n                while(curr < sessionTime) {\n                    if(state[diff] > 0) {\n                        curr += diff;\n                        state[diff]--;\n                    }\n                    else {\n                        diff--;\n                        if(diff <= 0) {\n                            break;\n                        }\n                    }\n                }\n                ans++;\n            }\n            if(state[i] == 0) {\n                i--;\n            }\n        }\n        return ans;\n    }\n};\n\n\n\n```
['Dynamic Programming', 'C']