Google software engineer interviews cover algorithms, data structures, system design, and coding problems drawn from real interview rounds.
Question Given a string where letters are sorted in alphabetical order, identify all letters that appear more than twice and record their first and...
Input: ArrayQuestion You are tracking GPS location errors by comparing measured GPS locations against a set of "golden" (reference) locations. Each location...
Input: ListQuestion Design a data structure to maintain a dynamic set of points on a 2D coordinate plane. Support operations to insert points, remove points,...
Input: ListQuestion Given a singly linked list, reverse the second half of the list and then interleave the nodes from the first half and the reversed second...
Input: Linked listQuestion You are given a range [A, B] and a sequence of painting operations. For each operation [L, R], calculate the total length of unpainted...
Input: Array of intervalsQuestion You are given a set of test cases and a black-box function runTests() that accepts a subset of these test cases and returns whether...
Question You are given an M x N garden grid and a list of crops, each requiring a specific number of plots. The total number of plots required by...
Input: 2D gridQuestion You are given an array A of integers. A triplet is a sequence of three consecutive elements. A triplet is called zero-sum if the...
Question A player is playing a game in which coins are placed on and removed from a table. The game consists of multiple rounds. At the beginning...
Input: Stringtext and a dictionary array where each element is in the format "<key>:<id>". Here key is a token string and id...Input: ArrayStreamBuffer 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)Question Design a PathRouter class that maps URL-like path patterns to handler names. Patterns may contain wildcard segments (*) that match any...
Question Given a string, build a Frequency Merge Tree as follows: 1. Count the frequency of each character in the string. 2. Create a leaf node...
Input: String+ and -, and parentheses ( and ), simplify...Input: Stringm x n binary grid where each cell is either '1' (land) or '0' (water). A group of connected land cells (connected horizontally...Input: 2D gridstart and end. Your task is to determine if there exists a path from start to end using DFS. The graph is undirected and can contain cycles. Return true if a path exists; otherwise, return false. def has_path(graph: List[List[int]], start: int, end: int) -> bool:graph = [[1, 2], [2, 3], [3], []], start = 0, end = 3 True 0 -> 1 -> 2 -> 3. graph = [[1], [2], [3], []], start = 0, end = 3 True 1 <= len(graph) <= 1000N neighbors.def dijkstra(graph: Dict[str, List[Tuple[str, int]]], start: str, target: str) -> Tuple[int, List[str]]:graph = { 'A': [('B', 1), ('C', 4)], 'B': [('C', 2), ('D', 5)], 'C': [('D', 1)], 'D': [] }, start = 'A', target = 'D'(4, ['A', 'B', 'C', 'D'])graph = { 'A': [('B', 2)], 'B': [('C', 2), ('D', 1)], 'C': [], 'D': [] }, start = 'A', target = 'C'(4, ['A', 'B', 'C'])def shortest_path(graph: Dict[int, List[Tuple[int, int]]], src: int, target: int) -> Tuple[int, List[int]]:graph = {0: [(1, 5), (2, 10)], 1: [(3, 3)], 2: [(3, 1)], 3: []}, src = 0, target = 3(8, [0, 1, 3])graph = {0: [(1, 2), (2, 4)], 1: [(2, 1), (3, 7)], 2: [(3, 3)], 3: []}, src = 0, target = 3(6, [0, 1, 2, 3])m x n, where each cell represents either a road (0) or an obstacle (1). You need to find the shortest path from the top-left corner (0,0) to the bottom-right corner (m-1,n-1). Return the length of the shortest path, or -1 if there is no path available. def shortestPath(grid: List[List[int]]) -> int: [[0,0,0],[0,1,0],[0,0,0]] 4 [[0,1,0],[1,1,0],[0,0,0]] -1 1 <= m, n <= 100 has_cycle(graph: List[List[int]]) -> bool that returns True if the given graph contains a cycle, and False otherwise.Function/class signature: def has_cycle(graph: List[List[int]]) -> bool: graph = [[1], [2], [0,3], [3]] True graph = [[1, 2], [2], [], [0]] False 1 <= len(graph) <= 10^4 1 <= len(graph[i]) <= 10^4 0 and len(graph) - 1 inclusive.-1. The graph's nodes are represented as integers from 0 to N-1 and edges are represented by pairs of integers (a, b) denoting an edge from a to b.def shortest_path_dag(edges: List[Tuple[int, int]], start: int, target: int, N: int) -> int:edges = [(0, 1), (1, 2), (2, 3)], start = 0, target = 3 3 0 -> 1 -> 2 -> 3, which has a length of 3. edges = [(0, 1), (0, 2), (2, 3)], start = 1, target = 3 -1 1 <= N <= 1000 0 <= edges.length <= 10000 0 <= start, target < N def shortest_path(edges: List[Tuple[int, int, int]], start: int, destination: int) -> Optional[int]: edges = [(0, 1, 2), (1, 2, 3), (0, 2, 7), (2, 3, 1)], start = 0, destination = 3 6 0 -> 1 -> 2 -> 3, which costs 2 + 3 + 1 = 6. edges = [(0, 1, 2), (1, 2, 3), (0, 2, float('inf')), (2, 3, 1)], start = 0, destination = 3 6 0 -> 1 -> 2 -> 3 is still valid and optimal. 1 <= len(edges) <= 10^4 0 <= start < max_node 0 <= destination < max_node float('inf') to denote closed roads.1s in a binary matrix.m x n binary matrix filled with 0s and 1s, your task is to return the area of the largest rectangle containing only 1s. You must implement maximalRectangle(matrix: List[List[int]]) -> int.Example 1:1s in the matrix.Constraints:m == matrix.lengthn == matrix[i].lengthO(m*n) time.findShortestPath(start: Point, end: Point) -> List[Point], which returns the shortest path as a list of Points from the start to the end. Assumptions include that the environment is represented as a 2D grid where passable and non-passable terrains are indicated.Point: A representation of a coordinate with x and y attributes.N x N with N ≤ 1000.0 and N-1.AutocompleteSystem that supports the following operations:input(char c: char) -> List[str]: Accepts a character and returns a list of the top 3 suggested terms that start with the current input string based on weighted frequency.addSentence(sentence: str, times: int) -> None: Adds a new sentence with its corresponding frequency.1000.100 characters.get(key: int) -> int: Returns the value of the key if the key exists, otherwise return -1.put(key: int, value: int) -> None: Update the value of the key if the key exists. Otherwise, add the key-value pair to the cache. If the number of keys exceeds the capacity from this operation, the least recently used key should be removed.10^4.Sign up for free to access walkthroughs, AI-generated questions, and more.
Get Started Free