Java HashMap solution with explanation
\nimport java.util.*;\n\nclass Solution {\n\n    /** Idea is to shift the whitelisted number up and \n        take the random index from 0 to whitelisted.length
```\nimport java.util.*;\n\nclass Solution {\n\n    /** Idea is to shift the whitelisted number up and \n        take the random index from 0 to whitelisted.length\n        \n        For e.g. N = 6\n        blacklist = {2, 3, 4}\n        \n        1, 2, 3, 4, 5, 6\n        w  b  b  b  w  w\n        \n        Only 3 whitelisted, \n        so swap 2 with 5 & swap 3 with 6\n        \n        which make the arr \n        1, 5, 6, 4, 2, 3\n        w  w  w  b  b  b\n        \n        And then take random number from 0 - whitelisted.lenth\n    */\n    Random r = new Random();\n    HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();\n    int wlen = 0;\n    public Solution(int N, int[] blacklist) {\n        int blen = blacklist.length;\n        wlen = N - blen;\n        \n        HashSet<Integer> set = new HashSet<Integer>();\n        //4, 5, 6\n        int from = wlen;\n        while(from <= N) {\n            set.add(from);\n            from++;\n        }\n        //System.out.println(set);\n        \n        //5, 6\n        for(int i = 0; i < blen; i++) {\n            set.remove(blacklist[i]);\n        }\n        //System.out.println(set);\n        \n        //Iterator over whitelist & blacklist and map\n        Iterator<Integer> itr = set.iterator();\n        for(int i = 0; i < blen; i++) {\n            //System.out.println("BlackList: "+blacklist[i]);\n            if(blacklist[i] < wlen) {\n                int e = itr.next();\n                //System.out.println("BlackList: "+blacklist[i]+" WhiteListing with "+e);\n                map.put(blacklist[i], e);\n            }\n        }\n        //System.out.println(map);\n    }\n    \n    public int pick() {\n        int rIndex = r.nextInt(wlen);\n        return map.getOrDefault(rIndex, rIndex);\n    }\n}\n    \n/**\n * Your Solution object will be instantiated and called as such:\n * Solution obj = new Solution(N, blacklist);\n * int param_1 = obj.pick();\n */\n```
[]