JAVA | Beat 100 % | Two Sum Idea | No bit-mask | No recursion |
```\n    public int minSessions(int[] tasks, int sessionTime) {\n\t\t//reverse order sort\n        tasks = Arrays.stream(tasks).boxed()\n            .sorted(Col
```\n    public int minSessions(int[] tasks, int sessionTime) {\n\t\t//reverse order sort\n        tasks = Arrays.stream(tasks).boxed()\n            .sorted(Collections.reverseOrder())\n            .mapToInt(Integer::intValue)\n            .toArray();\n        \n        //Key is tasks[i], Value is counter\n        Map<Integer, Integer> map = new HashMap<>();\n        for(int t : tasks) {\n            map.put(t, map.getOrDefault(t, 0) + 1);\n        }\n        \n        int count = 0;\n        for(int t : tasks) {\n            if(map.get(t) > 0) {\n                map.put(t, map.get(t) - 1);\n                int cur = t;\n                int temp = sessionTime - cur;\n                while(cur < sessionTime) {\n                    if(map.getOrDefault(temp, 0) > 0) {\n                        cur += temp;\n                        map.put(temp, map.get(temp) - 1);\n                    } else {\n                        temp--;\n                        if(temp == 0) {\n                            break;\n                        }\n                    }\n                }\n                count++;\n            }\n        }\n        return count;  \n    }\n\n\t
[]