Nebius Interview Question

Design a new data structure with O(1) time complexity for add/delete/get/get_random methods. Why accessing value by key in the dict structure is Average O(1) time complexity. Write an algorithm to compress strings like AAAABB into A4B2 with no extra memory.