n people labeled from 0 to n - 1. Some pairs of people know each other directly. These relationships are given as a...Input: ListTwitter class that supports the following methods:postTweet(userId: int, tweetId: int) -> None: Record a new tweet.getNewsFeed(userId: int) -> List[int]: Retrieve the 10 most recent tweet IDs in the user's news feed.follow(followerId: int, followeeId: int) -> None: Allow a follower to follow a followee.unfollow(followerId: int, followeeId: int) -> None: Allow a follower to unfollow a followee.Method Signatures:def postTweet(self, userId: int, tweetId: int) -> Nonedef getNewsFeed(self, userId: int) -> List[int]def follow(self, followerId: int, followeeId: int) -> Nonedef unfollow(self, followerId: int, followeeId: int) -> NoneExample 1:twitter = Twitter()twitter.postTweet(1, 5)twitter.getNewsFeed(1)[5]Example 2:twitter.follow(1, 2)twitter.postTweet(2, 6)twitter.getNewsFeed(1)[6, 5]Constraints:0 <= userId, followerId, followeeId, tweetId <= 10^410^4. At most 3 * 10^4 follow operations will occur.LRUCache class that supports get(key: int) -> int and put(key: int, value: int) -> None methods. The cache will have a limited capacity.def get(self, key: int) -> int: Returns the value of the key if present, otherwise -1.def put(self, key: int, value: int) -> None: Updates the value of the key or adds it if it's not already present. When the cache reaches its capacity, it invalidates the least recently used item before inserting a new item.Example 1:cache = LRUCache(2)cache.put(1, 1)cache.put(2, 2)cache.get(1)1Example 2:cache.put(2, 1)cache.put(2, 2)cache.get(2)2Constraints:capacity will be between 1 and 3000.key and value are integers within the range of a 32-bit signed integer.nums, implement a function maxSubArray(nums: List[int]) -> int that returns the largest sum of contiguous elements in the array.def maxSubArray(nums: List[int]) -> int: Returns the maximum sum of a contiguous subarray.Example 1:nums = [-2,1,-3,4,-1,2,1,-5,4]6[4,-1,2,1] has the largest sum 6.Example 2:nums = [1]1Constraints:1 <= nums.length <= 10^5-10^4 <= nums[i] <= 10^4dijkstra(graph: Dict[int, List[Tuple[int, int]]], start: int) -> Dict[int, int] that calculates the shortest path from a starting node to all other nodes.def dijkstra(graph: Dict[int, List[Tuple[int, int]]], start: int) -> Dict[int, int]: Returns a dictionary where keys are node indices and values are the shortest distances from the start.Example 1:graph = {0: [(1, 4), (2, 1)], 1: [(3, 1)], 2: [(1, 2), (3, 5)], 3: []}, start = 0{0: 0, 1: 3, 2: 1, 3: 4}0 to node 3 is through 2 and then to 1.Example 2:graph = {0: [(1, 2)], 1: [(2, 3)], 2: [(3, 1)], 3: []}, start = 0{0: 0, 1: 2, 2: 5, 3: 6}Constraints:1 <= len(graph) <= 10^40 <= graph[i][j][0] < len(graph)0 < graph[i][j][1] <= 10^3Sign up for free to access walkthroughs, AI-generated questions, and more.
Get Started Free