Javascript 240ms Map()
First, add all the blacklist[] values into a new Map() (with dummy values -99)\n\nSo we want to pick a random number, check the hash map, and return something e
First, add all the blacklist[] values into a new Map() (with dummy values -99)\n\nSo we want to pick a random number, check the hash map, and return *something else*\nif it was a blacklisted value.  Historically speaking (Fisher Yates) that something else would\nbe the last values of the original list.  So the last three values if N=1000 are 997, 998, 999.\nWe need to not use those numbers, twice... somehow.\n\nThe solution is to shorten our random range (instead of 0-999, it becomes 0-996)\nSo we pick a random number 0-996.  If that lands on a blacklisted number,\nwe substitute 997, 998, or 999.  The "Last" variable keeps track of this value.\n\nBut... what if one of our blacklisted numbers *is* 998?\n\nWe keep track of the size of the list without blacklisted values.\nSo in this example, it\'s 1000-3 (for the total number of blacklisted values). As stated,  when we\nthrow away 3 values our new list size is 997 (0-996).  Any blacklisted values above 996 don\'t\neven get to play the substitution game.  They get ignored entirely.\n\nIn the code where it says "if (blacklist[i] < max) {" --- that\'s where we ignore blacklisted\nnumbers that are larger than max.  Max is the original list size (N) minus the size of the\nblacklist.\n\nAlso, we have to somehow manage that 998 is blacklisted and can\'t be used as a substitute.\nThere\'s a tight loop that check if Last (the value we are using as a substitute) *is* blacklisted.\n\nThis piece of code is where we skip blacklisted values as substitutes.\n```\nwhile(this.subst.has(Last)) { Last--; }\n```\n\nHere\'s the prog:\n```\nvar Solution = function(N, blacklist) {\n    let i, Last;\n    this.subst = new Map();\n    for(i = 0; i < blacklist.length; i++) { this.subst.set(blacklist[i], -99); }\n    Last = N-1;\n    let max = N-(blacklist.length);\n    for(i = 0; i < blacklist.length; i++) {\n        if (blacklist[i] < max) {\n            while(this.subst.has(Last)) { Last--; }\n            this.subst.set(blacklist[i],Last);\n            Last--;\n        }\n    }\n    this.last = max;\n}\n/**\n * @return {number}\n */\nSolution.prototype.pick = function() {\n    let r = Math.trunc(Math.random() * (this.last));\n    if(this.subst.has(r)) { return this.subst.get(r); }\n    return r;\n};\n```
['JavaScript']