Number Game - Company-specific OAs / Amazon OA

https://algo.monster/problems/amazon_oa_number_game

What is “mask”? Can we get an explanation on that?

This solution is missing the memo/mask idea of your solution. I don’t understand the mask concept. Help?

var maxScore = function(nums) {
return dfs(nums, 1, {});
}
function dfs(nums, ithOperation, memo) {
// this feels like class top down dfs.
if(nums.length == 0) return 0;
// i have no idea what ‘mask’ is.
let max = 0;
for(let i = 0; i < nums.length-1; i++) {
for(let j = i+1; j < nums.length; j++) {
let val_to_add = gcd(nums[i], nums[j]) * ithOperation;
let val1 = nums.splice(i, 1)[0];
let val2 = nums.splice(j-1, 1)[0]; // subtract one because i being removed changed things.
max = Math.max(max, val_to_add + dfs(nums, ithOperation+1, memo));
nums.splice(i, 0, val1);
nums.splice(j, 0, val2);

    }
}
return max;

};

function gcd(x, y) {
// a priority queue maybe?
if(y == 0) return x;
return gcd(y, x % y);
}

Update - just study the bitmask section under dynamic programming. facepalm.

https://www.youtube.com/watch?v=uySUx0FFly0

Please add some explanation here