xAI software engineer interviews cover algorithms, data structures, system design, and coding problems drawn from real interview rounds.
n environmental sensors labeled 0 to n - 1. Each sensor is either functioning correctly or corrupted, but you do...Input: Listnums, return the maximum sum of non-adjacent elements. Specifically, if you choose an element, you cannot choose the elements immediately before or after it. def max_sum_non_adjacent(nums: List[int]) -> int: nums = [2, 4, 6, 2, 5] 13 nums = [1, 2, 3, 1] 4 1 <= len(nums) <= 100 0 <= nums[i] <= 400 Tokenizer class that allows you to add words and tokenize sentences into a list of words. The tokenizer should be able to handle spaces and punctuation correctly. The key methods should utilize a trie data structure, which enables efficient storage and retrieval of words. class Tokenizer: def add_word(self, word: str) -> None: def tokenize(self, sentence: str) -> List[str]: tokenizer = Tokenizer() tokenizer.add_word("hello") tokenizer.add_word("world") output = tokenizer.tokenize("hello world!") ['hello', 'world'] tokenizer.tokenize("xAI is amazing.") ['xAI', 'is', 'amazing'] KthLargest that keeps track of the kth largest element in a dynamically updating stream of integers. The class should support the method add(int val), which adds an integer to the stream and returns the current kth largest element.class KthLargest:def __init__(self, k: int, nums: List[int]) -> None:def add(self, val: int) -> int: k = 3, nums = [4, 5, 8, 2] KthLargest kthLargest = KthLargest(k, nums) kthLargest.add(3) 4 3, the third largest number is 4. Example 2: kthLargest.add(5) 5 5. Constraints: 1 <= k <= 104 0 <= nums.length <= 104 -104 <= nums[i] <= 104 -104 <= val <= 104 104 calls will be made to add. None) in an input list of integers. The function should return the indices of the None values in ascending order.def find_missing_indices(data: List[Optional[int]]) -> List[int]: find_missing_indices([1, None, 3, None, 5]) [1, 3] find_missing_indices([None, None, 2, 4]) [0, 1] data will have at most 10^4 elements. None. def shortest_path(graph: List[List[int]], start: int, end: int) -> int:graph = [[1, 2], [0, 2, 3], [0, 1], [1]], start = 0, end = 3 2 graph = [[1], [0, 2], [1, 3], [2]], start = 0, end = 3 3 1 <= graph.length <= 1000 0 <= start, end < graph.length 0 <= graph[i].length <= 1000nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum.int max_sub_array_sum(List<int> nums): returns the maximum sum of the contiguous subarray.1 <= nums.length <= 3 * 10^4-10^4 <= nums[i] <= 10^4.List[int] bfs_shortest_path(int start, int target): returns the list of integers representing the path from start to target.1 <= start, target <= 10^410^4 nodes and 2 * 10^4 edges.def shortestPath(graph: Dict[int, List[int]], start: int, target: int) -> List[int]: returns a list of node values representing the shortest path.Example 1: graph = {0: [1, 2], 1: [3], 2: [3], 3: []}, start = 0, target = 3 [0, 1, 3] graph = {0: [1], 1: [2], 2: [3], 3: []}, start = 0, target = 2 [0, 1, 2] 1 <= graph.length <= 1000 nums, return the length of the longest increasing subsequence.def lengthOfLIS(self, nums: List[int]) -> int: returns the length of the longest increasing subsequence found in nums.Example 1: nums = [10, 9, 2, 5, 3, 7, 101, 18] 4 [2, 3, 7, 101], therefore its length is 4.Example 2: nums = [0, 1, 0, 3, 2, 3] 4 [0, 1, 2, 3], therefore its length is 4.Constraints: 1 <= nums.length <= 2500 -10^4 <= nums[i] <= 10^4UserSessionManager 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