Simple Java solution with explanation : O(B) 
Trick is to realize two things: \n\n1) map the integers in BlackList to the numbers towards the end, so that the new range to generate the random number would c
Trick is to realize two things: \n\n1) map the integers in BlackList to the numbers towards the end, so that the new range to generate the random number would come down to [0, N - BlackList.size())\nfor ex: if B = [4] and range is [0,8) then after mapping 4 to 8, the new range would be  [0,7) and if the random number generates 4, we return 8 using the mapping.\n\n2) While mapping we need to ensure that the number to which we are maping the blackListed number k, is not already blackListed. for ex: \nif B = [2, 6,8] and range: [0,8) then we should not map 2 to 6 or 8.  \n\nCode below should be self explanatory  and handles the above two cases. \n\n``` \nclass Solution {\n\n    Map<Integer, Integer> bToValid = new HashMap<>();\n    int allowedCap;\n    Random r;\n    \n    public Solution(int N, int[] blacklist) {\n        r = new Random();\n\t\t\t\t\n\t\t\t\t// initialize the map with -1 for the numbers in BlackList so that its easier to handle 2). \n        for(int b : blacklist){\n            if(b < N){\n                bToValid.put(b, -1);         \n            }\n        }\n        allowedCap = N - bToValid.size();\n        N = N-1;\n\t\t\t\t\n\t\t\t\t// create the mapping\n        for(int b : blacklist){\n            if(b < allowedCap){\n                while(bToValid.containsKey(N))\n                    N--;\n                bToValid.put(b, N--);\n            }\n        }\n    }\n    \n    public int pick() {\n        int num = r.nextInt(allowedCap);\n        if(bToValid.size() > 0 && bToValid.containsKey(num) ){\n            num =  bToValid.get(num);   \n        }\n        return num;\n    }\n}\n\n\n```
[]