xAI software engineer interviews cover algorithms, data structures, system design, and coding problems drawn from real interview rounds.
No verified questions yet for xAI.
now_ms. Before performing that operation, remove every request whose expiration time is at most now_ms. Expiration is arrival_ms + ttl_ms. Time is nondecreasing across calls, and expiration takes precedence over selection or cancellation.submit returns false if its ID is already pending after expiration cleanup; otherwise it appends the request and returns true. Duplicate submissions must not update the existing request. An ID may be reused after its request expires, is canceled, or is dispatched.max_tokens; its pending request count is at least max_requests; or its oldest pending request has waited at least max_wait_ms. Among ready models, choose the model whose oldest pending request was inserted earliest. Insertion order, not model-name order, breaks equal-arrival-time ties.next_batch removes and returns exactly one batch for the selected model. Take the longest nonempty prefix of that model's insertion-ordered queue that fits both limits. Stop at the first request that would exceed a limit: do not skip it to fit smaller requests behind it. If no model is ready, return an empty list. A readiness threshold is based on the entire model queue, even when only a short prefix fits.GrokRequestBatcher(max_tokens: int, max_requests: int, max_wait_ms: int) — construct an empty batcher with fixed limits.submit(request_id: str, model: str, tokens: int, now_ms: int, ttl_ms: int) -> bool — clean up expired requests, then attempt to enqueue a request.cancel(request_id: str, now_ms: int) -> bool — clean up expired requests, then remove the specified pending request; return whether it existed.next_batch(now_ms: int) -> list[str] — clean up expired requests, select one ready model, and return dispatched IDs in that model's queue order.pending(now_ms: int) -> list[str] — clean up expired requests and return all remaining IDs in global insertion order.text:{
"config": {"max_tokens": 10, "max_requests": 3, "max_wait_ms": 50},
"calls": [
["submit", "a", "text", 6, 0, 100],
["submit", "b", "text", 5, 1, 100],
["submit", "c", "text", 4, 2, 100],
["next_batch", 2],
["next_batch", 3],
["next_batch", 51],
["pending", 51]
]
}[true, true, true, ["a"], [], ["b", "c"], []]
text is ready because its total reservation is 6 + 5 + 4 = 15 >= 10 and its count is 3. The batch contains only a: adding b would use 11 tokens, and skipping b to include c is forbidden. At time 3, the remaining total is 9 and the oldest request has waited only 2 ms. At time 51, b has waited exactly 50 ms, so b and c dispatch together.Example 2:{
"config": {"max_tokens": 8, "max_requests": 2, "max_wait_ms": 20},
"calls": [
["submit", "x", "text", 3, 0, 10],
["submit", "y", "vision", 4, 1, 100],
["submit", "z", "vision", 4, 2, 100],
["next_batch", 2],
["submit", "w", "text", 5, 3, 100],
["cancel", "w", 4],
["pending", 10],
["cancel", "x", 10],
["submit", "x", "text", 8, 10, 5],
["submit", "x", "text", 1, 10, 100],
["next_batch", 10]
]
}[true, true, true, ["y", "z"], true, true, [], false, true, false, ["x"]]
vision is ready: its two requests reserve 4 + 4 = 8 tokens. The older text request does not block it. Request w is canceled, and the original x expires exactly at time 10. Its ID can then be reused. The second submission of the new x is rejected without changing its 8-token reservation, so it dispatches immediately.Constraints1 <= max_tokens <= 1,000,000, 1 <= max_requests <= 1,000, and 0 <= max_wait_ms <= 1,000,000.1 <= tokens <= max_tokens; 1 <= ttl_ms <= 1,000,000.UserSessionManager class is critical for xAI to handle user sessions securely and efficiently. It requires proper management of user logins, session timeouts, and session validation to ensure a consistent user experience across devices.login(user_id: str) -> str: Logs in a user and returns the session ID.logout(session_id: str) -> None: Logs out a user by invalidating their session ID.is_valid_session(session_id: str) -> bool: Checks if the session ID is valid.get_session_data(session_id: str) -> dict: Retrieves the session data associated with a session ID.4. Example 1:login('user123') → Output: session_id_abcuser123 successfully logs in and receives a session ID.5. Constraints:POST /train, GET /predict, and GET /status. Ensure to consider versioning and error handling in your design.1000 concurrent requests with low latency.put(key: int, value: int): void and get(key: int): int. When the cache reaches its capacity, it should invalidate the least recently used (LRU) item. class LRUCache:def __init__(self, capacity: int): Initializes the cache with a positive size capacity.def get(self, key: int) -> int: Returns the value of the key if the key exists, otherwise returns -1.def put(self, key: int, value: int) -> None: Updates or adds the value if the key is not present. When the cache reaches its capacity, it should invalidate the least recently used item before adding the new item.1 <= capacity <= 30000 <= key <= 100000 <= value <= 10^9.get(key: int) -> int: Retrieve the value of the key if the key exists in the cache, otherwise return -1.put(key: int, value: int) -> None: Update the value of the key if the key exists. If the key does not exist, add the key-value pair to the cache. If the cache reaches its capacity, it should invalidate the least recently used item before inserting a new item.def get(self, key: int) -> intdef put(self, key: int, value: int) -> Nonecache = LRUCache(2), cache.put(1, 1), cache.put(2, 2), cache.get(1) 1 Example 2: cache.put(3, 3), cache.get(2) -1 capacity is at most 3000.Sign up for free to access walkthroughs, AI-generated questions, and more.
Get Started Free