Java Solution | Backtrack + Recursion + Memoization
Solution:\n\n\nArrayList<Integer> sessions;\nHashMap<Pair<ArrayList<Integer>, Integer>,Integer> memo;\n\npublic int minSessions(int[] tasks, int sessionTime) {\
Solution:\n\n```\nArrayList<Integer> sessions;\nHashMap<Pair<ArrayList<Integer>, Integer>,Integer> memo;\n\npublic int minSessions(int[] tasks, int sessionTime) {\n\tsessions = new ArrayList();\n\tmemo = new HashMap();\n\treturn recursive(tasks, sessionTime, 0);\n}\n\nprivate int recursive(int[] tasks, int sessionTime, int currentPos){\n\t//Base case\n\tif(currentPos>=tasks.length){\n\t\treturn 0; //No tasks take zero sessions\n\t}\n\tPair<ArrayList<Integer>, Integer> pair = new Pair(new ArrayList(sessions), currentPos);\n\tif(memo.containsKey(pair)){\n\t\treturn memo.get(pair);\n\t}\n\n\t//We can always add a new session\n\tsessions.add(tasks[currentPos]);\n\tint result = 1 + recursive(tasks, sessionTime, currentPos+1);\n\t//Backtrack\n\tsessions.remove(sessions.size()-1);\n\n\t//Other cases are trying to add to current sessions\n\tfor(int i=0;i<sessions.size();i++){\n\t\tif(sessions.get(i)+tasks[currentPos]<=sessionTime){\n\t\t\tsessions.set(i, sessions.get(i)+tasks[currentPos]);\n\t\t\tresult = Math.min(result, recursive(tasks, sessionTime, currentPos+1));\n\t\t\tsessions.set(i, sessions.get(i)-tasks[currentPos]);   //Backtrack\n\t\t}\n\t}\n\tmemo.put(pair, result);\n\treturn result;\n}\n```\n\nInspired by C++ solution by @Invulnerable: https://leetcode.com/problems/minimum-number-of-work-sessions-to-finish-the-tasks/discuss/1431836/C%2B%2B-Solution-or-Recursion-%2B-Memoization
['Backtracking', 'Recursion', 'Memoization', 'Java']