Google Software Engineer Coding & Algorithms Interview Questions
Master your tech interview with our curated database of real questions from top companies.
Parse strings and find meeting slots
Question Given a text file where each line contains raw information, extract the user identifier and the numeric quantity on that line and store the r...
Remove elements to avoid k-prefix duplicates
Question Given two lists listA and listB and an integer k, delete elements from listB so that the first k elements of the new listB share no value wit...
Find shortest path with blocked nodes
Question Given an unweighted graph, a start node, an end node, and a block_set of nodes that cannot be traversed, return the length of the shortest pa...
Compute city skyline outline
You are given a list of rectangular buildings in a 2D city skyline. Each building is represented by three integers [L, R, H]: - L: the x-coordinate of...
Shuffle array using random integer API
You are given an array nums of length n representing a deck of distinct cards. You do not have access to a built-in shuffle function, but you are give...
Find maximum value in huge text file
You are given the path to a very large text file on disk. The file has the following properties: - Each line contains exactly one signed 64-bit intege...
Find longest duplicated substring
You are given a string s consisting of lowercase English letters. A substring of s is any contiguous sequence of characters, i.e., s[i..j) for 0 ≤ i <...
Find largest digit-sharing subset
You are given an array of N integers. Each integer has exactly two decimal digits (i.e., each element is between 10 and 99 inclusive). You want to cho...
Design an elevator control system
Design the software for a multi-elevator control system in a high-rise building. Specify classes, scheduling algorithms for car assignments, handling ...
Group movies via graph traversal
You are given n movies labeled 0..n-1 and a list of undirected pairs (a, b) meaning movies a and b are similar. Group all movies into categories where...
Find fair split of a two-color necklace
Given a circular necklace represented by a string s over {'a','b'}, you may cut the necklace at most twice (yielding three contiguous pieces). Can you...
Count user sessions from logs
Given a large log file where each line is "timestamp,user,action", compute the number of sessions per user. Assume a session ends if the gap between c...
Design server allocation for multi-type nodes
Design a service to manage a large pool (about 100, 000) of server nodes. Each node can satisfy multiple instance types; clients call getServer(reqNum...
Find minimum covering substring
Given two strings s and t, return the shortest contiguous substring of s that contains every character of t with at least the same multiplicities. If ...
Optimize 0/1 to bounded knapsack DP
Solve the 0/1 knapsack problem: given arrays weight[i], value[i] for i=0..n-1 and capacity W, return the maximum value and reconstruct one optimal set...
Troubleshoot CPU, latency, and DNS issues
A) A Linux server’s CPU usage suddenly spikes. What immediate checks and commands would you run (e.g., top/htop, pidstat, perf, iostat), how would you...
Compute shortest paths with blocked nodes
Given a graph with nodes and edges and a designated source node s, compute the shortest distance from s to every other node. Some nodes are inaccessib...
Find horizontal cut balancing square areas
Given a 2D table with top-left origin (0, 0), you are provided a finite set of n non-overlapping, axis-aligned square cakes. Each square i has real-va...
Design autocomplete with Trie
Design and implement an autocomplete service using a prefix tree (Trie). Support operations insert(word, weight), update(word, newWeight), delete(word...
Maintain k-th largest in a stream
Design and implement a class KthLargest that, given an integer k and an initial list of integers, supports: ( 1) KthLargest(k, nums): constructor; ( 2...