xAI software engineer interviews cover algorithms, data structures, system design, and coding problems drawn from real interview rounds.
nums, 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^4put(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