Leave your Email to get the latest Google interview questions weekly.
We'll never share your email with anyone else.
No spam we promise.
Design instagram auction system, both static and live...
Given an extensible string, find the letter at a target index...
Design Online Chess Game...
Design the theme and style marketplace, for example on Atlassian, where you can buy themes for your Atlassian products...
Given a list of circles denoted by center(x,y) and radius, return if all circles are in the same group...
Write a function to return the area of the largest island with inland lakes...
Design Google image reverse search. Users can upload a raw image and search related images. Users can also search by the image URL...
How to use Queues in your system?
Design the smart lock system...
Design a version control system like GitHub…
Design a chat app like FB Messenger/Whatsapp/Slack and search the chat history by keywords…
Design the playlist sharing feature on Spotify...
Design a file sharing app like Google Drive/Dropbox/Box…
Build a text editor class with the following functions: moveCursorLeft(),moveCursorRight(), insertCharacter(char), backspace()...
Design the user autocomplete model in the google search bar....
Given a string, sort only the lower case letters and return. Also the lower case letters should remain in the same place...
You have been assigned a task to process the user login status log. Each row in the log is an API request. There are three sign-in related APIs: Register, Login and Logout...
Given a matrix, a robot is located at the top left corner and needs to reach the bottom right corner of the matrix. Return the path with the minimum delta of all paths from the upper left corner to the bottom right corner...
Given a binary tree, each leaf node value can be true or false. Each non-leaf node value can be OR, AND. Return the result of the binary tree...
Think about ads platform like Google/Meta. There are billions of ads clicks per day. Now we need to design a dashboard to visualize the ads performance. More specifically, you need to implement a service to return the number of ads clicks within a certain time frame...
Given a gallery of images, implement a class to support searching image...
Given a word and N six-sided dice with char on each side, find out whether it's possible to construct the word by rolling the dices...
Find out if a given string is periodic...
A pizza shop offers n pizzas along with m toppings. A customer plans to spend around x coins. The customer should order exactly one pizza, and may order zero, one or two toppings. Each topping may be ordered only once.
Given the lists of prices of available pizzas and toppings, what is the price closest to x of possible orders? Here, a price said closer to x when the difference from x is the smaller. Note the customer is allowed to make an order that costs more than x.
Given a binary tree and two nodes, return the path from one node to the other node...
1. Google Robot in Maze Problem - Count Number of Ways in Matrix
1.2 Count Number of Ways with Obstacles in Matrix
1.3 Count Number of Ways Detour for North
Given a matrix noted as 0 or 1, return the shortest distance to the boundary. The definition of boundary is the points which has at least one 0 neighbors...
Implement a function to get the books of a given genre...
You task is to build a line chart for the server load change through time, given a sequence of load rate data. Each data point is a pair of numerics [int timestamp, double rate]. The timestamp starts from 0 and naturally increments by 1 per data point...
In a 2d array, a cell has either '/' or '\' as its value.
The matrix has N columns. N balls are dropped from the top of the matrix, one at each column...
Implement a function that finds the number of '*' in the input string, excluding the '*' between a pair of '|'...
Find the union set of two data streams and remove any duplicated elements.
Given an array of integer of size N, select K numbers from the array...
Delete a given list of nodes from a binary tree and return the roots of all remaining (sub)trees after the deletion...
Given a 2d array with two rows, find out the number of non-empty subarrays filled with 0. A subarray may have either 1 or 2 rows...
Build a function to check whether an IPv4 address is a bot in the black list. The robot ip black list is given as a list of strings. Each string has 3 dots and 4 segments of numbers between 0 and 255...
Find out the disjointed elements of two arrays. The disjointed elements are those that remain after common elements of the arrays are removed...
Given an array of integer, find out the number of non-empty subarrays filled with 0.
Given a matrix of parentheses, find if there exists a path from upper left corner to the bottom right corner that forms a valid parentheses.
Online Judege Demo. Currently support Python and Java.
Find the longest diameter of a tree. The diameter of a tree is defined as the number of edges on the longest path in the tree.
Given an array of integers representing the value of coupons, return the minimum number of consecutive coupons to pick up to win the prize.
Given a n*n 2D array. Fill the integer from 1 to n*n to this 2D array that makes the sum of each row, each column and the two diagonal equal.
Given a BST, and an integer k, cut the BST vertically into two substrees A and B, where all nodes in A <= k and all nodes in B > k.
Contrain: for any node A and it’s parent B in the original BST. If after the cut they are both in the same subtree. B should still be the parent of A.
Given an int array of length n. Split it into strictly decreasing subsequences. Return the minimum number of decreasing subsequences you can get by splitting the array.
Given an array represents the bloom dates of a list of roses, return the earliest day that we can get n bouquets of roses...
Amazon Online Assessment Question: Find the minimum cost to repair the edges so that all the nodes are once again accessible from each other.
[Google Onsite Question] Zombie in Matrix Problem
In a 2d array of integer, 2 denotes wall, 1 denotes zombie and 0 denotes human...
Given a String, find the minimum number of deletions required to convert it into a palindrome.
...
Given two two integer arrays, find the longest common subsequence.
eg: a =[1 5 2 6 3 7], b = [5 6 7 1 2 3]. return [1 2 3] or [5 6 7]
Design and implement the Least Recently Used Cache with TTL(Time To Live)
Expalnation on the eviction stragedy since people have questions on the testcase:
1, after the record expires, it still remains in the cache.
2, when the cache reaches the capacity, it first evicts the expried records. If there are more than one expired records, evict the one with the minimum expire timestamp.
...
Given an integer n, return the representations in Fibonacci base for the integer from 1 to n.
...
Given a binary grid where 0 represents water and 1 represents land. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. Delete all islands except their borders. A border is land adjacent to water. You may assume all four edges of the grid are surrounded by water
There are n students [0, ..., n-1] participate in a marathon. You are given an int array standings where standings[i] = j means that student j finished just before student i. Return the students in the order in which they finished the marathon.
Given a secret word and encoding rules as follows: Each letter can be changed to a different letter. Different letters can not be changed to the same letter. For example, banana can be encoded to xyzyzy, but banana cannot become xyyyyy, because there is no way to decode it back. Also given an encoded string str, return true if and only if this string contains the specified secret word.
Given 2 strings pin and guess. Write a function to provide a hint that indicates how digits in guess match the pin.
Given an array return an integer indicating the minimum number of swap operations required to sort the array into ascending order.
Given two strings s and t, determine if you can convert s into t.
Given an integer N which represents number of edges, where bases are always 2.Find how many trapezoid you can create with the integer N?
Normal palindrome is defined as a string that reads the same backwards as forwards, for example "abccba".
Given a run-length encoded string s and a width of a board. Assume that the board is filled from left to right such that each line has exactly width chars. Return the run-length encoded string that represents the board rows from right to left without constructing the board.
Given 2 run-length encoded strings s and t. Determine if they represent the same string.
Tree Game
Two people in a game, player scores by claiming nodes in binary tree, tree node class as shown above.
The player who eventually owns more nodes wins the game.
Player A and B each claims a node at first.
After the first round, a player will only be able to claim a node adjacent to any node owned by himself.
A tree node is adjacent to its parent, left right and right child.
A node owned cannot be re-claimed.
End game when all nodes are owned.
If player A gets the first claim at node N, find whether it is possible for player B to win.
If yes, find out which node player B should claim at his first move.
Given the left view and front view of the skyline of a block as two arrays, find the maximum total height of buildings in the block.
Build a text editor class with the following functions,
moveCursorLeft(),
moveCursorRight(),
insertCharacter(char) //insert the char right before cursor
backspace() //delete the char right before cursor
Google On-site 2018 Winter
There are orbs on an NxM board ('O' denotes orb. 'X' denotes empty slot).
Whenever two orbs are in the same column or the same row, you get to erase one of them.
Try to erase as many orbs as possible.
Find the minimum number of orbs remained on board eventually.
How to randomly select a number in an array?
array: [15, 2, 4, 5, 1, -2, 0]
Follow-up:
Given a second array freq where freq[i] represents the occurrence of the ith number in array, how to randomly select a number in array based on the frequency.
Extra requirement:
Could you complete the selection in a single-pass(go through each array only once)?
Give a binary tree, find if it's possible to cut the tree into two halves of equal sum. You can only cut one edge.
Design and implement a data structure for a compressed string iterator. It should support the following operations: next and hasNext. The given compressed string will be in the form of each letter followed by a positive integer representing the number of this letter existing in the original uncompressed string.
For example, UNIQ("LETTER") = 2.
Given a string S with only uppercases, calculate the sum of UNIQ(substring) over all non-empty substrings of S.
If there are two or more equal substrings at different positions in S, we consider them different. Since the answer can be very large, retrun the answer modulo 10 ^ 9 7.In the array {1, 6, 3, 5, 9, 7}, the longest arithmetic sequence is 1, 3, 5, and 7
Given the length and width of a matrix, get the number of paths from bottom-left to bottom right.
Implement a ring buffer
Give an array A of n integers where 1 <= a[i] <= K. Find out the length of the shortest sequence that can be constructed out of numbers 1, 2, .. k that is NOT a subsequence of A.
Implement an iterator to flatten a 2d vector.
Given a binary tree, return the values of its boundary in anti-clockwise direction starting from root. Boundary includes left boundary, leaves, and right boundary in order without duplicate nodes.