Implement weighted random sampling with preprocessing | Meta Interview Question