Google logo

Google Interview Questions

21 practice questions for Google technical interviews

coding Medium Verified

Dictionary of Sorted Letters


Category: Array coding problem
# 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: Array
Output: Computed result
coding Medium Verified

GPS Error Tracking


Category: Algorithm coding problem
# Question You are tracking GPS location errors by comparing measured GPS locations against a set of "golden" (reference) locations. Each location...
Input: List
Output: Computed result
coding Hard Verified

Minimum Boxing Area


Category: Binary search coding problem
# Question Design a data structure to maintain a dynamic set of points on a 2D coordinate plane. Support operations to insert points, remove points,...
Input: List
Output: Integer
coding Medium Verified

Reverse Segment of Linked List


Category: Linked list coding problem
# Question 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 list
Output: Computed result
coding Medium Verified

Unpainted Segments


Category: Binary search coding problem
# Question 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 intervals
Output: Computed result
coding Medium Verified

Running Tests With Failing Pairs


Category: Algorithm coding problem
# Question 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...
Input: List
Output: Integer
coding Medium Verified

Connected Crop Allocation


Category: Grid/matrix coding problem
# 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 grid
Output: Computed result
coding Medium Verified

[CodeSignal] Maximum Zero-Sum Triplets


Category: Array coding problem
# Question 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...
Input: Array
Output: Computed result
coding Easy Verified

[CodeSignal] Coin Table Game


Category: String coding problem
# 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: String
Output: Computed result
coding Medium Verified

Longest Match Tokenizer


Category: Array coding problem
You are given a text string text and a dictionary array where each element is in the format "<key>:<id>". Here key is a token string and id...
Input: Array
Output: Computed result
coding Hard Verified

Dual Extremes Queue


Category: Queue-based coding problem
Design a StreamBuffer 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)
Output: Integer
coding Medium Verified

Daily Branch Pruning


Category: Tree coding problem
A file system manages a directory tree. Each day, all leaf directories (those with no child directories) are simultaneously removed. Directories that...
Input: Array
Output: Array
coding Medium Verified

Path Router


Category: Algorithm coding problem
# Question Design a PathRouter class that maps URL-like path patterns to handler names. Patterns may contain wildcard segments (*) that match any...
Input: Number(s)
Output: Computed result
coding Medium Verified

Frequency Merge Tree


Category: Tree coding problem
# 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
Output: Computed result
coding Hard Verified

Expression Simplifier


Category: String coding problem
Given an algebraic expression string containing single lowercase-letter variables, the operators + and -, and parentheses ( and ), simplify...
Input: String
Output: Computed result
coding Medium Verified

Largest Island Perimeter


Category: Grid/matrix coding problem
You are given an m x n binary grid where each cell is either '1' (land) or '0' (water). A group of connected land cells (connected horizontally...
Input: 2D grid
Output: Computed result
coding Hard Verified

Interval Coverage Counter


Category: Interval-based coding problem
Given a list of closed intervals on the integer number line, build a data structure that efficiently answers point-coverage queries. A closed...
Input: List
Output: Computed result
system design Hard api design

[OA] Design a Google-like Search Autocomplete System

As Google’s search engine evolves, providing suggestions while users type is critical for enhancing search quality and user experience. Your task is to design an autocomplete system that suggests search terms based on previously entered queries.
Problem statement: Design a class 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.
Example 1:
Input:
autocompleSystem = new AutocompleteSystem();
autocompleSystem.addSentence("i love you", 5);
autocompleSystem.addSentence("island", 5);
output = autocompleSystem.input('i');
// returns ["i love you", "island"]
Example 2:
Input:
autocompleSystem = new AutocompleteSystem();
autocompleSystem.addSentence("hi", 2);
output = autocompleSystem.input('h');
// returns ["hi"]
Constraints:
- The input will only be lowercase English letters.
- The total number of sentences will not exceed 1000.
- Each sentence has at most 100 characters.
system design Hard cache

[OA] LRU Cache — Implement a caching layer for Google API responses

In optimizing the performance of Google’s services, managing frequently accessed data is key. Implement an LRU Cache for the API calls to minimize latency and server calls.
Problem statement: Implement an LRUCache class with the following methods:
- 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.
Example 1:
Input:
lruCache = LRUCache(2);
lruCache.put(1, 1);
lruCache.put(2, 2);
output1 = lruCache.get(1); // returns 1
lruCache.put(3, 3); // evicts key 2
output2 = lruCache.get(2); // returns -1 (not found)
Example 2:
Input:
lruCache = LRUCache(1);
lruCache.put(2, 1);
output1 = lruCache.get(2); // returns 1
lruCache.put(3, 2); // evicts key 2
output2 = lruCache.get(2); // returns -1 (not found)
Constraints:
- The capacity of the cache will be at most 10^4.
- The keys are guaranteed to be unique within the cache.
coding Hard dynamic programming

[OA] Dynamic Programming — Maximal Rectangle in Google Cloud’s BigQuery

In managing large datasets, Google Cloud’s BigQuery requires efficient computations to determine the largest rectangular area defined by 1s in a binary matrix.
Problem statement: Given a 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:
Input: matrix = [[1,0,1,0,0],[1,0,1,1,1],[1,1,1,1,1],[1,0,0,1,0]]
Output: 6
Explanation: The largest rectangle has an area of 6.
Example 2:
Input: matrix = [[0,0,0],[0,0,0]]
Output: 0
Explanation: There are no 1s in the matrix.
Constraints:
- m == matrix.length
- n == matrix[i].length
- Area must be computed in O(m*n) time.
coding Senior graph

[OA] A* Search Algorithm — Implement the routing algorithm used for real-time traffic updates

In Google's Maps, real-time navigation requires efficient pathfinding over large graphs representing cities and road networks. Your task is to implement the A* search algorithm to find the shortest path between two points.
Problem statement: You need to implement the method 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.
Example 1:
Input: start = (0, 0), end = (3, 3)
Output: [(0, 0), (1, 1), (2, 2), (3, 3)]
Explanation: The algorithm finds an optimal path through the grid.
Example 2:
Input: start = (1, 1), end = (4, 4)
Output: [(1, 1), (2, 2), (3, 3), (4, 4)]
Explanation: Another optimal path is provided based on proximity.
Constraints:
- The grid size will be at most N x N with N ≤ 1000.
- Points coordinates will be between 0 and N-1.

Start practicing Google questions

Sign up for free to access walkthroughs, AI-generated questions, and more.

Get Started Free