Beasts 100% users || JS || Fully explained
\n# Code\n\nlet MOD = 1000000007; // Define the modulo value\nlet sumsMapPre = Array(20001).fill(0); // Initialize an array to store the prefix sum counts\nlet 
![image.png](https://assets.leetcode.com/users/images/a2252cc3-29a8-4505-b7ee-cfc607478b5f_1713557262.5571039.png)\n# Code\n```\nlet MOD = 1000000007; // Define the modulo value\nlet sumsMapPre = Array(20001).fill(0); // Initialize an array to store the prefix sum counts\nlet sumsMapCur = Array(20001).fill(0); // Initialize an array to store the current sum counts\nlet sumsArr = Array(20001).fill(0); // Initialize an array to store the sums\n\n/**\n * Function to count the number of sub-multisets in a given range.\n * @param {number[]} nums - The array of numbers.\n * @param {number} l - The left bound of the range.\n * @param {number} r - The right bound of the range.\n * @return {number} - The count of sub-multisets in the specified range.\n */\nvar countSubMultisets = function(nums, l, r) {\n  let n = nums.length; // Get the length of the input array\n  nums.sort(); // Sort the input array\n  \n  // Initialize the prefix sum arrays and variables\n  sumsMapCur.fill(0);\n  sumsMapPre.fill(0);\n  sumsMapCur[0] = 1;\n  let t = 0;\n  let tt = 0;\n\n  let acc = 0; // Initialize an accumulator variable\n  \n  // Iterate through the numbers in the input array\n  for (let i = 0; i < n; i++) {\n    if (nums[i] == nums[i - 1]) acc += nums[i]; // Accumulate the sum if the current number is the same as the previous one\n    else {\n      tt = t; // Update the temporary variable tt\n      acc = nums[i]; // Update the accumulator variable\n\t  \n      // Update the sumsMapPre and sumsMapCur arrays\n      for (let j = t; j >= 0; j--) {\n        sumsMapPre[sumsArr[j]] = (sumsMapCur[sumsArr[j]] + sumsMapPre[sumsArr[j]]) % MOD;\n        sumsMapCur[sumsArr[j]] = 0;\n      }\n    }\n\n    // Calculate the counts of sub-multisets for each sum\n    for (let j = tt; j >= 0; j--) {\n      let newSum = sumsArr[j] + acc; // Calculate the new sum\n      if (newSum <= r) {\n        if (!sumsMapCur[newSum] && !sumsMapPre[newSum]) {\n          sumsArr[++t] = newSum; // Store the new sum in the sumsArr array\n        }\n\n        // Update the counts in sumsMapCur\n        let cnt = (sumsMapPre[sumsArr[j]] + sumsMapCur[newSum]) % MOD;\n        sumsMapCur[newSum] = cnt;\n      }\n    }\n  }\n\n  let res = 0; // Initialize the result variable\n  // Calculate the final result by summing the counts within the specified range\n  for (let i = l; i <= r; i++) {\n    res = (res + sumsMapPre[i] + sumsMapCur[i] ?? 0) % MOD;\n  }\n\n  return res; // Return the final result\n};\n\n```
['JavaScript']