Cracking the Google Coding Interview
By: The Educative Team
Tags: Interview, Interview Tips, Programming, Coding Interview, Startup

Part 3. Coding Interview Question Guide

Practicing for coding questions takes a lot of time, effort, and focus. Let’s break down the top Google coding questions, as well as actionable advice to prepare.

Top 15 Google coding interview questions

Find the Kth largest element in a number stream.

Problem statement: Design a class to efficiently find the Kth largest element in a stream of numbers. The class should have the following two things: ​

The constructor of the class should accept an integer array containing initial numbers from the stream and an integer K.

The class should expose a function add(int num) which will store the given number and return the Kth largest number.

2. Find K closest numbers.

Problem statement: Given a sorted number array and two integers K and X, find K closest numbers to X in the array. Return the numbers in the sorted order. X is not necessarily present in the array.

3. Delete node with given key.

Problem statement: You are given the head of a linked list and a key. You have to delete the node that contains this given key.

4. Copy linked list with arbitrary pointer.

Problem statement: You are given a linked list where the node has two pointers. The first is the regular next pointer. The second pointer is called arbitrary_pointer , and it can point to any node in the linked list.

Your job is to write code to make a deep copy of the given linked list. Here, deep copy means that any operations on the original list (inserting, modifying, and removing) should not affect the copied list.

5. Mirror binary trees.

Problem statement: Given the root node of a binary tree, swap the left and right children for each node.

6. Find all paths for a sum.

Problem statement: Given a binary tree and a number S, find all paths from root-to-leaf such that the sum of all the node values of each path equals S.

7. Find the length of the longest substring with no more than K distinct characters.

Problem statement: Given a string, find the length of the longest substring in it with no more than K distinct characters.

8. Find the longest substring with no repeating characters.

Problem statement: Given a string, find if its letters can be rearranged in such a way that no two same characters come next to each other.

9. Find equal-sum subset partition.

Problem statement: Given a set of positive numbers, find if we can partition it into two subsets such that the sum of elements in both subsets is equal.

10. Determine if the number is valid.

Problem statement: Given an input string, determine if it makes a valid number or not. For simplicity, assume that white spaces are not present in the input.

11. Print balanced brace combinations.

Problem statement: Print all braces combinations for a given value N so that they are balanced.

12. Given a number of tasks, determine if they can all be scheduled.

Problem statement: There are N tasks, labeled from 0 to N-1. Each task can have some prerequisite tasks that need to be completed before it can be scheduled. Given the number of tasks and a list of prerequisite pairs, find out if it is possible to schedule all the tasks.

13. Implement an LRU cache.

Problem statement: Least Recently Used (LRU) is a common caching strategy. It defines the policy to evict elements from the cache to make room for new elements when the cache is full, meaning it discards the least recently used items first.

14. Find the high and low index.

Problem statement: Given a sorted array of integers, return the low and high index of the given key. Return -1 if not found. The array length can be in the millions, with many duplicates.

15. Merge overlapping intervals.

Problem statement: You are given an array (list) of interval pairs as input where each interval has a start and end timestamp. The input array is sorted by starting timestamps. You are required to merge overlapping intervals and return output array (list).

12-week preparation roadmap

Preparing for a Google coding interview is strategic. It requires months of prep and practice to master the right concepts and develop confidence. Let’s look at the definitive twelve-week prep plan proven to help candidates land jobs at big companies.

Week 0. Choose a programming language based on Google’s expectations and your preferences.

Week 1. Review the basics of your programming language. If you brush up on the basics, you’re less likely to stumble during your interview. Review concepts like how to read input from the console, and how to declare and use 2D arrays.

Week 2 & 3. Familiarize yourself with data structures and algorithms. These are essential to coding interviews with Google.

Data structures you should know:

Arrays

Linked lists

Stacks

Queues

Trees

Graphs

Heaps

Hash sets

Hash maps/tables

Algorithms you should know:

Breadth-first search

Depth-first search

Binary search

Quicksort

Mergesort

A*

Dynamic programming

Divide and conquer​

Week 4 & 5. Practice data structure and algorithmic challenges with sites like Educative or Leetcode. Start practicing simple coding problems. This will make it easier down the line to tackle harder questions.

Weeks 6–8. Practice complex coding problems, and start timing yourself. It’s important to consider runtime and memory complexity for each solution.

Weeks 9 & 10. Study system design interview questions. These are now an integral part of the interview process and impact your hiring level.

Week 11. Study OS and concurrency concepts. These questions are used to gauge your hiring level. Brush up on multithreading fundamentals to stand out for higher levels in Google’s ladder.

Week 12. Study object-oriented programming and design questions. These questions gauge your critical thinking, project-based problem-solving skills.

Tips for practicing coding challenges

There is no shortcut or magic wand for practicing coding challenges. Here are some basic tips to guide you through the preparation stage.

Keep time in mind. The coding interview will be timed, so it’s important to prepare with that in mind. If you are used to preparing under a time constraint, it will be far less stressful during the actual interview.

Know your weak spots. As you prepare, take note of your weak spots. Everyone has them. Google has stated that they care about your thought process, so if you come up against a weak spot, talk through it. This will demonstrate your eagerness to improve.

Know the common pitfalls. There are three big pitfalls when it comes to a Google interview: not knowing the Big-O complexity of an algorithm, having no knowledge of Google’s expectations, and not articulating your problem-solving process. Keep these pitfalls in mind as you work.

Articulate your process. Google wants to hear about your thought process. As you practice, get used to explaining why and what you are doing. Those with a clear sense of how they work stand out.