Java
\n\n# Code\n\nclass Solution {\n\n    int len,n;\n    Map <Integer, Integer>  map; \n    Random r;\n    public Solution(int n, int[] blacklist) {\n        // ma
\n\n# Code\n```\nclass Solution {\n\n    int len,n;\n    Map <Integer, Integer>  map; \n    Random r;\n    public Solution(int n, int[] blacklist) {\n        // map blacklist into the cells  {n - blacklist.length : n}, call random(0:n - blacklist.length) and if we land on blacklist return the mapping instead\n        len = blacklist.length;\n        this.n = n; \n        map = new HashMap();\n        for (int i = 0; i < len ; i++) map.put(blacklist[i] , n - len + i);\n        for (int i = 0; i < len ; i++) map.put(blacklist[i] , find(map.get(blacklist[i]))); // remove chains optimization\n        r = new Random();\n    }\n\n    private int find(int x){ \n        if (!map.containsKey(x) || map.get(x) <= x) return x;\n        return find(map.get(x));\n    }\n    \n    public int pick() {\n        int rand = r.nextInt(n - len);\n        while (map.containsKey(rand)) rand = map.get(rand);\n        return rand;\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```
['Java']