JavaScript and TypeScript Bitmask DP
DP[mask][time] = Minimum number of work sessions after assigning task by mask and it remains time session time\n\nJavaScript\njs\n/**\n * @param {number[]} task
DP[mask][time] = Minimum number of work sessions after assigning task by `mask` and it remains `time` session time\n\nJavaScript\n```js\n/**\n * @param {number[]} tasks\n * @param {number} sessionTime\n * @return {number}\n */\nvar minSessions = function(tasks, sessionTime) {\n  const n = tasks.length;\n  const dp = Array(1 << n).fill().map(() => Array(16).fill(-1));\n  \n  const solve = (mask, time) => {\n    if (mask === (1 << n) - 1) {\n      return 1;\n    }\n    \n    if (dp[mask][time] !== -1) {\n      return dp[mask][time];\n    }\n    \n    let min = Infinity;\n    for (let i = 0; i < n; ++i) {\n      if (mask & (1 << i)) {\n        continue;\n      }\n\n      if (time >= tasks[i]) {\n        min = Math.min(\n          min,\n          solve(mask | (1 << i), time - tasks[i]),\n        );\n      } else {\n        min = Math.min(\n          min,\n          1 + solve(mask | (1 << i), sessionTime - tasks[i]),\n        );\n      }\n    }\n    \n    dp[mask][time] = min;\n    return min;\n  }\n  \n  return solve(0, sessionTime);\n};\n\n```\n\nTypeScript\n```ts\nfunction minSessions(tasks: number[], sessionTime: number): number {\n  const n = tasks.length;\n  const dp = Array(1 << n).fill(null).map(() => Array(16).fill(-1));\n  \n  const solve = (mask, time) => {\n    if (mask === (1 << n) - 1) {\n      return 1;\n    }\n    \n    if (dp[mask][time] !== -1) {\n      return dp[mask][time];\n    }\n    \n    let min = Infinity;\n    for (let i = 0; i < n; ++i) {\n      if (mask & (1 << i)) {\n        continue;\n      }\n\n      if (time >= tasks[i]) {\n        min = Math.min(\n          min,\n          solve(mask | (1 << i), time - tasks[i]),\n        );\n      } else {\n        min = Math.min(\n          min,\n          1 + solve(mask | (1 << i), sessionTime - tasks[i]),\n        );\n      }\n    }\n    \n    dp[mask][time] = min;\n    return min;\n  }\n  \n  return solve(0, sessionTime);\n};\n```
['TypeScript', 'JavaScript']