✅Beginner friendly explanation with comments - beats 100% - C++✅
Explanation\ntrick ye hai manle ki 20 numbers hai aur unme se 5 tere blacklist number h toh\nnon-backlist tere hue 20 - 5 = 15 toh 15 non-blacklist ho gaye. m k
# Explanation\ntrick ye hai manle ki 20 numbers hai aur unme se 5 tere blacklist number h toh\nnon-backlist tere hue 20 - 5 = 15 toh 15 non-blacklist ho gaye. m kya karunga 0-15 numbers tak jaunga, ab 15 ke baad toh 5 number bachege. m kya karunga ki\nuss 15 numbers ke andar jo blacklist number h usko m 15 ke baad wale\nnon-blacklist number se map karwa dunga. ye m map lekr karunga toh kya hoga ki\nrandom number toh tu non-blacklit ke liye hi nikalega kyuki tujhe chahiye toh\nnon blacklist hi, bole toh 0 - 15 ke beech toh agr jo tunne random number nikala\nagr ye tera blacklist h toh m kya karunga ki uske corresponding jo non blacklist\nh vo return kardunga ni toh jo number generate kiya that will be a non-blacklist\ntoh I\'ll return that.\n\n# Complexity\n- Time complexity: O(B)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    unordered_map<int, int> mp;\n    int valid_range;\n    Solution(int n, vector<int>& blacklist) {\n        // set le liya h toh sort karne ki need ni, iske andar automatically\n        // sorted hi milega\n        set<int> st;\n        for (auto numbers : blacklist) {\n            st.insert(numbers);\n        }\n\n        // kis range tak hi number niklege ki kitne non-blacklist h\n        valid_range = n - blacklist.size();\n\n        int lastNum = valid_range;\n\n        for (auto number : st) {\n            // jo range ke andar ho aur blacklist ho, toh aise number se map\n            // karunga jo range ke bahar ho par non-blacklist ho\n            // sabse pehle check karunga ki range ke andar hai vo blacklist\n            // number...then range ke bahar ka number mapk karwaunga jo st ke\n            // andar na ho bole toh blacklist na ho\n            if (number < valid_range) {\n                while (st.count(lastNum)) {\n                    lastNum++;\n                }\n                mp[number] = lastNum;\n                lastNum++;\n            }\n        }\n    }\n\n    int pick() {\n        int random = rand() % valid_range;\n        if (mp.count(random)) {\n            return mp[random];\n        }\n        return random;\n    }\n};\n/*\ntrick ye hai manle ki 20 numbers hai aur unme se 5 tere blacklist number h toh\nnon-backlist tere hue 20 - 5 = 15 toh 15 non-blacklist ho gaye. m kya karunga 0\n- 15 numbers tak jaunga, ab 15 ke baad toh 5 number bachege. m kya karunga ki\nuss 15 numbers ke andar jo blacklist number h usko m 15 ke baad wale\nnon-blacklist number se map karwa dunga. ye m map lekr karunga toh kya hoga ki\nrandom number toh tu non-blacklit ke liye hi nikalega kyuki tujhe chahiye toh\nnon blacklist hi, bole toh 0 - 15 ke beech toh agr jo tunne random number nikala\nagr ye tera blacklist h toh m kya karunga ki uske corresponding jo non blacklist\nh vo return kardunga ni toh jo number generate kiya that will be a non-blacklist\ntoh I\'ll return that.\n\n*/\n\n```
['C++']