[Java] share my simple DFS backtracking solution with pruning, beats 91%
\n\nclass Solution {\n    int min;\n    public int minSessions(int[] tasks, int sessionTime) {\n        min = tasks.length + 1; // upper bound, any result can\'
\n```\nclass Solution {\n    int min;\n    public int minSessions(int[] tasks, int sessionTime) {\n        min = tasks.length + 1; // upper bound, any result can\'t over this upper bound\n        \n        Arrays.sort(tasks);\n        reverse(tasks);\n        dfs(tasks, 0, new int[tasks.length], sessionTime, 0);\n        return min;\n    }\n    private void dfs(int[] tasks, int start, int[] bucket, int target, int count) {\n        if(count >= min) {\n            return; // pruning\n        }\n        \n        if (start == tasks.length) {\n            min = count;\n            return;\n        }\n        \n        // refer to this: https://leetcode.com/problems/find-minimum-time-to-finish-all-jobs/discuss/1009817/One-branch-cutting-trick-to-solve-three-LeetCode-questions\n        Set<Integer> seen = new HashSet<>(); \n        for (int i = 0; i < bucket.length; i++) {\n            if (seen.contains(bucket[i])) {\n                continue;\n            }\n            if (tasks[start] + bucket[i] > target) {\n                continue;\n            }\n            if(bucket[i] == 0) {\n                // new task period, count++\n                count++;\n            }\n            seen.add(bucket[i]);\n            \n            bucket[i] += tasks[start];\n            dfs(tasks, start+1, bucket, target, count);\n            bucket[i] -= tasks[start];\n        }\n        \n    }\n   \n    private void reverse(int[] nums) {\n        int left = 0;\n        int right = nums.length-1;\n        while (left < right) {\n            int temp = nums[left];\n            nums[left] = nums[right];\n            nums[right] = temp;\n            left++;\n            right--;\n        }\n    }\n}\n\n```
['Backtracking', 'Depth-First Search', 'Java']