TikTok software engineer interviews cover algorithms, data structures, system design, and coding problems drawn from real interview rounds.
n broadcast stages, numbered 1 to n, arranged in a perfect binary tree rooted at stage 0. Each stage...Input: Binary treeM x N grid of security zones. Each cell contains one of the following values: - 1 -- the zone is cleared - 0 -- the zone...Input: 2D gridStreamBuffer class that buffers a stream of integer latency samples in FIFO order and supports O(1) access to both the minimum and maximum...Input: Integer(s)signal of 0s and 1s representing antenna readings logged in sequence, where 1 means good signal and 0 means...Input: Arraypattern and a log string, both consisting of uppercase letters and the wildcard character *. The * wildcard matches...Input: Stringbudgets (integers) and an integer k representing the number of throttle operations available. Each operation selects...Input: ListcouponsCount discount coupons and a list of monthly service fees. Each coupon halves one service fee using integer floor division....Input: Listtracks and a positive integer k. Remove exactly k consecutive tracks from the list so that the sum of...Input: Array'S' - your starting position - 'C' - the...Input: 2D gridCdnRouter that maps URL paths to origin servers using longest-prefix matching. Implement the following methods: -...Input: Stringtags: the tag name for...Input: ArrayA to user B means that user A follows user B, write a function to find all strongly connected components (SCCs) in the graph. An SCC is a subgraph where every vertex can be reached from every other vertex. Implement the function find_scc(graph: List[List[int]]) -> List[List[int]] that returns a list of lists, where each inner list is a component.def find_scc(graph: List[List[int]]) -> List[List[int]]:graph = [[1], [2], [0], [4], [5], [4]] [[0, 1, 2], [4, 5]] 4 follows 5.graph = [[1], [], [3], [2]] [[0, 1], [2, 3]] 0 connects to 1, forming an SCC. Nodes 2 and 3 form another because each can reach the other.1 <= graph.length <= 1000 0 <= graph[i].length <= graph.length n integers representing the duration of videos, your task is to find if there exists a pair of videos such that their duration sums up to a target value targetDuration. Return the indices of these two videos in an array.def find_video_pair(videos: List[int], targetDuration: int) -> List[int]:videos = [20, 15, 30, 10, 25], targetDuration = 35 [0, 2] videos = [10, 5, 7, 8], targetDuration = 17 [1, 3] 2 <= n <= 10^4 1 <= videos[i] <= 10^3 1 <= targetDuration <= 2 * 10^3 cost where cost[i] is the cost to obtain a video at index i. You also have a target integer targetViews, which is the number of total views you want to achieve. Your task is to determine the minimum cost to obtain videos from the cost array such that the total number of views reaches or exceeds targetViews. Return the minimum cost. If it is impossible to achieve the target, return -1. def minCost(cost: List[int], targetViews: int) -> int: cost = [1,2,3,4,5], targetViews = 5 5 cost = [1,2,3], targetViews = 6 -1 1 <= len(cost) <= 100 1 <= cost[i] <= 1000 0 <= targetViews <= 1000 cost is guaranteed to be greater than or equal to targetViews if possible.videoIds representing the videos that users watched and a corresponding array of viewCounts that represents how many times each video was watched, you need to write a function that finds the k most watched videos. The function should return a list of video IDs in descending order of views.def most_watched_videos(videoIds: List[str], viewCounts: List[int], k: int) -> List[str]:videoIds = ['v1', 'v2', 'v3', 'v4'], viewCounts = [100, 250, 150, 250], k = 2['v2', 'v4']v2 and v4 have the highest views (250).videoIds = ['a', 'b', 'c', 'd'], viewCounts = [20, 10, 30, 30], k = 3['c', 'd', 'a']c and d both have 30 views, and a has 20 views.1 <= len(videoIds), len(viewCounts) <= 10^51 <= viewCounts[i] <= 10^61 <= k <= len(videoIds)VideoMetadataCache that can store and retrieve video metadata based on video IDs. The cache should automatically evict the least recently used (LRU) entry when it reaches a maximum capacity. You need to implement two methods: get(video_id: str) -> Optional[dict] to retrieve metadata and put(video_id: str, metadata: dict) -> None to store metadata.def get(video_id: str) -> Optional[dict]:def put(video_id: str, metadata: dict) -> None:put('v1', {'title': 'Video 1', 'views': 1000}) get('v1') {'title': 'Video 1', 'views': 1000} put('v2', {'title': 'Video 2', 'views': 2000}) put('v3', {'title': 'Video 3', 'views': 3000}) put('v4', {'title': 'Video 4', 'views': 4000}) get('v1') None def shortest_path_videos(graph: Dict[str, List[str]], start: str, target: str) -> List[str]:graph = {"A": ["B", "C"], "B": ["C", "D"], "C": ["D"], "D": []}; start = "A"; target = "D"['A', 'B', 'D']graph = {"A": ["B", "C"], "B": ["E"], "C": ["D", "E"], "D": [], "E": []}; start = "A"; target = "E"['A', 'B', 'E']Sign up for free to access walkthroughs, AI-generated questions, and more.
Get Started Free