c++ random approach works
People have pointed out that sorting the tasks and then greedily add each task cannot solve the problem, but we can try randomly shuffle the tasks and use the g
People have pointed out that sorting the tasks and then greedily add each task cannot solve the problem, but we can try randomly shuffle the tasks and use the greedy approach. It works for this problem since the data set is not so large. \n```\nclass Solution {\npublic:\n    int minSessions(vector<int>& tasks, int sessionTime) {\n        \n        int res = INT_MAX;\n        \n        for (int i = 0; i < 5000; ++i) {\n            \n            random_shuffle(tasks.begin(), tasks.end());\n            \n            res = min(res, calculate(tasks, sessionTime));\n        }\n        \n        return res;\n    }\n    \n    \n    int calculate(vector<int> &tasks, int sessionTime) {\n        \n        int res = 1, crr = 0;\n        \n        for (auto &task : tasks) {\n            \n            if (crr + task <= sessionTime)\n                crr += task;\n            else {\n                ++res;\n                crr = task;\n            }\n        }\n        return res;\n    }\n};\n```
[]