Apple backend engineer interviews typically focus on APIs, databases, system design, concurrency, caching, and data structures.
No verified questions yet for Apple.
MessageQueue with the following methods:def __init__(self): - Initializes the messaging queue.def send(self, message: str) -> None: - Sends a new message to the queue.def receive(self) -> str: - Receives the oldest message from the queue, returning it.def size(self) -> int: - Returns the current number of messages in the queue.Example 1:mq = MessageQueue() followed by mq.send('Hello')Nonemq.receive() after the previous send'Hello''Hello', is returned.Constraints:1 <= message.length <= 1001 <= number of messages <= 10^4RateLimiter that provides the following methods:def __init__(self, limit: int, time_window: int): - Initializes the rate limiter with a specified request limit and time window.def request(self, user_id: str) -> bool: - Determines if a request from user_id should be allowed based on current limits.def cleanup(self): - Cleans up expired requests from the records.Example 1:limiter = RateLimiter(5, 10) followed by limiter.request('user1')Trueuser1 is accepted.Example 2:limiter.request('user1', 5) five timesFalse1 <= limit <= 1001 <= time_window <= 601 <= Number of Requests <= 10^4k, return the maximum number of active connections at any given time within the last k seconds.- def max_active_connections(times: List[int], k: int) -> int: returns the maximum number of connections.Example 1:times = [1, 2, 5, 6, 7], k = 335, there are 3 active connections (from 3 to 5).Example 2:times = [1, 2, 3, 4, 5], k = 224 and 5, the number of active connections within k=2 seconds is 2.Constraints:1 <= len(times) <= 10^51 <= k <= 10^3def dijkstra(graph: Dict[int, List[Tuple[int, int]]], source: int) -> Dict[int, int]: returns a dictionary mapping each node to its shortest distance from the source.Example 1:graph = {0: [(1, 4), (2, 1)], 1: [(3, 1)], 2: [(1, 2), (3, 5)], 3: []}, source = 0{0: 0, 1: 3, 2: 1, 3: 4}0 to all other nodes are calculated.Example 2:graph = {0: [(1, 2)], 1: [(2, 5)], 2: []}, source = 0{0: 0, 1: 2, 2: 7}0.Constraints:1 <= len(graph) <= 10^50 <= source < len(graph)Sign up for free to access walkthroughs, AI-generated questions, and more.
Get Started Free