Java - 1ms - bitmask & backtracking recursion - Easy recursive thinking
Idea / Intuition\n I thought of having individual slots for each task as each of them is less than sessionTime, as that would be the requirement in worst case.\
**Idea / Intuition**\n* I thought of having individual slots for each task as each of them is less than sessionTime, as that would be the requirement in worst case.\n* So for each new element we need to recur for an old slot with time>= current element time and one full empty slot.\n* To prune we can keep slotCount and when it is >= already found mincount we prune.\n\n***Improvement tip:***\nWithout sorting - 950ms\nSorting - 43ms\nDescending sort - 1ms\n\n\n```\nclass Solution {\n\t//simple reversing array logic ignore\n    public static void reverse(int[] input) { int last = input.length - 1; int middle = input.length / 2; for (int i = 0; i <= middle; i++) { int temp = input[i]; input[i] = input[last - i]; input[last - i] = temp; } }\n    static int minSlotsNeeded;\n    public int minSessions(int[] tasks, int sessionTime) {\n        int n=tasks.length;\n        minSlotsNeeded = 10000;\n        Arrays.sort(tasks);\n        reverse(tasks); // descending\n        int[] allSlots = new int[n];\n        Arrays.fill(allSlots, sessionTime);\n        rec(tasks, 0, allSlots, sessionTime, 0);\n        return minSlotsNeeded;\n    }\n    static int rec(int[] tasks, int elems, int[] slots, int limit, int slotCount) {\n        if(slotCount>=minSlotsNeeded) return 10000; // pruning if current slot utilization exceeds already found min\n        int elem=-1;\n        for(int i=0;i<tasks.length && elem==-1;i++) // finding out first unselected element\n            if((elems>>i & 1)==0) elem=i;\n        if(elem==-1) { // if no element unselected then see if the slot count can better minSlotsNeeded\n            int count = 0;\n            for(int a: slots)\n                if(a<limit) count++;\n            minSlotsNeeded = Math.min(minSlotsNeeded, count);\n            return count;\n        }\n        elems = elems | 1<<elem;\n        //all non full to be attempted for unselected task until incl first full slot\n        int minSlots = 10000;\n        for(int i=0;i<tasks.length;i++) {\n            if(slots[i]>=tasks[elem]) {\n                slots[i]-=tasks[elem];\n                int slcount = slots[i]+tasks[elem] == limit? slotCount+1 : slotCount; // to inc slotCount if new slot otherwise old count stays\n                minSlots = Math.min(minSlots, rec(tasks, elems, Arrays.copyOf(slots, slots.length), limit, slcount));\n                slots[i]+=tasks[elem];\n                if(slots[i]==limit) break; // if this is the first full slot we finished recursion for then we can stop\n            }\n        }\n        \n        return minSlots;\n    }\n}\n```
['Backtracking', 'Java']