Home/Blog/Interview Prep/Top 10 common MAANG coding interview questions
Home/Blog/Interview Prep/Top 10 common MAANG coding interview questions

Top 10 common MAANG coding interview questions

12 min read
Jan 17, 2025
content
#1: Two Sum
#2: 3 Sum
#3: Integer to English Words
#4: Number of Islands
#5: Merge Sorted Array
#6: Lowest Common Ancestor of a Binary Tree
#7: Kth Largest Element in an Array
#8: Longest Substring Without Repeating Characters
#9: Trapping Rain Water
#10: Best Time to Buy and Sell Stock
Level up your skills and keep practicing

Preparing for a MAANG interview? You're in the right place!

Today, we're breaking down the top 10 coding questions you're most likely to encounter in a technical interview with Meta, Amazon, Apple, Netflix, or Google—along with tips and tricks to help you tackle each one like a pro.

Here's a look at what we'll cover:

Let's begin!

#1: Two Sum#

In this problem, you are given an array of numbers and a target number. Your task is to find two numbers from the array so that their sum equals the target. Return the indexes of these two numbers. A couple of pointers:

  • Each array element can be used only once, e.g., you need to look for the required pair at two different indexes.

  • There will always be exactly two numbers in the array whose sum equals the target, ensuring that one unique solution exists.

Now, an intuitive way to solve this problem is to use nested loops to go over each pair of numbers in the array.

The outer loop iterates through each element in the array, and for each element, the inner loop checks all subsequent elements to see if any of them, when added to the current element, equal the target. When the sum of a pair matches the target value, return the indexes of those numbers.

Problem solved, right? But hold on ... there's a catch.

What are the time and space complexities? This solution has a time complexity of O(n^2) due to the nested loop and a constant space complexity of O(1) since no additional data structures are used. For larger arrays, this approach is inefficient. We need a solution with a better time complexity than O(n^2).

The time and space complexities are important because they guide you toward finding an optimized solution. Make sure to revise them before you go for any interview.

This problem is commonly asked in interviews because it tests your understanding of time and space complexity. It challenges you to use data structures effectively to find an optimized solution.

Instead, there are two optimized approaches you can take to solving this problem.

One way to reduce the O(n^2) time complexity from nested loops is by using a single loop and a hash map. For each element, calculate the difference between the target sum and the current number, then check if this difference is in the hash map. If it is, you’ve found the pair. If not, add the current number to the hash map and continue. This approach has both time and space complexity of O(n).

It's time to move on to the next frequently asked common coding problem. However, we encourage you to keep thinking about the other optimal solutions for the Two Sum problem.

#2: 3 Sum#

This problem is an extension of Two Sum, and it's likely that interviewers ask it as a follow-up of Two Sum.

Tip: It is very important to read the problem statement carefully. If you spend enough time understanding what’s required, you'll come up with the correct solution in less time.

In the 3 Sum problem, you’re given an array of numbers and your task is to find and return all unique sets of three numbers that sum up to zero. Each set should consist of distinct elements from the array.

Can you take some time to identify the similarities and differences between the Two Sum and 3 Sum problems? Consider the details of each problem and how they affect the solution.

1

Which statement correctly states the time complexity of the optimal solutions for the 3 Sum problem?

A)

It has the same time complexity as the Two Sum, O(n)O(n), in its optimal solutions.

B)

It requires O(n2)O(n^2) in its optimal solution.

C)

It requires O(n3)O(n^3) in its optimal solution.

Question 1 of 20 attempted

The most common first attempt is to use three nested loops to check all possible triplets. While simple to implement, this approach is inefficient with a time complexity of O(n^3), making it impractical for large arrays.

Here are two optimized approaches to consider:

  • Hash Set Approach: Start by sorting the array in ascending order. For each element, treat it as the first number in a triplet. Then, use a helper function—similar to the Two Sum approach—to find two additional numbers that sum to zero with this element. A hash set helps track previously seen numbers, avoiding duplicates. Skipping repeated numbers ensures each triplet is unique. This approach has a time complexity of O(n^2) and a space complexity of O(n log n) due to sorting.

  • Two-pointer technique: First, sort the array. For each element, apply two pointers to find pairs that sum to zero with the current element. Skip duplicates to ensure unique triplets. This technique also has a time complexity of O(n^2) and a space complexity of O(n log n) due to sorting."

You can find a detailed solution, including an explanation, slides illustrating the algorithm steps, and code, in the Sum of Three Values lesson of Grokking Coding Interview Patterns in Python.

Another problem that extends 3 Sum and Two Sum is 4 Sum, which you can explore in the 4 Sum problem. Now, let's move to our next problem.

Recommended by Educative

Cover
Grokking the Coding Interview Patterns

With thousands of potential questions to account for, preparing for the coding interview can feel like an impossible challenge. Yet with a strategic approach, coding interview prep doesn’t have to take more than a few weeks. Stop drilling endless sets of practice problems, and prepare more efficiently by learning coding interview patterns. This course teaches you the underlying patterns behind common coding interview questions. By learning these essential patterns, you will be able to unpack and answer any problem the right way — just by assessing the problem statement. This approach was created by FAANG hiring managers to help you prepare for the typical rounds of interviews at major tech companies like Apple, Google, Meta, Microsoft, and Amazon. Before long, you will have the skills you need to unlock even the most challenging questions, grok the coding interview, and level up your career with confidence. This course is also available in JavaScript, Python, Go, and C++ — with more coming soon!

85hrs
Intermediate
318 Challenges
319 Quizzes

#3: Integer to English Words#

In this problem, you are given a nonnegative integer, and your task is to convert it to its English words version.

Seems like a straightforward problem statement, right? But short statements often mean interviewers are leaving plenty for you to uncover. Be mindful of brief problem descriptions and consider all possible rules, constraints, and edge cases to ensure you arrive at the correct solution.

Always keep an eye for edge cases and practice handling complex rules because these skills are important for solving many real-world problems.

In the context of this problem, a few points to consider:

  • It requires handling various cases in number conversion, such as ones, tens, hundreds, thousands, and so on.

  • What is the range of our input? What is the maximum value we might encounter?

  • Ensure that a single space separates all the words and there are no trailing spaces.

There are several ways to solve this problem, each with their own advantages. Let's look at the most common one:

  • Mapping to representation: Convert numbers into their English word representations. First, break down the number into three-digit chunks. Process each chunk individually to get its word form, then combine these chunks with their respective place values (e.g., thousand, million). Starting with the least significant chunk, append each place value in sequence until you have the full word representation.

Now, let’s look at the code for this approach:

def number_to_words(num):
if num == 0:
return "Zero"
# Store the word representations of the numbers from 1 to 19
below_20 = ["One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven",
"Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen"]
# Store the word representations of tens numbers
tens = ["Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety"]
# Store the word representations of thousands numbers
thousands = ["", "Thousand", "Million", "Billion"]
# Function to find word representation of a three-digit number
def represent(n):
if n == 0:
return ""
elif n < 20:
return below_20[n-1] + " "
elif n < 100:
return tens[n // 10 - 2] + " " + represent(n % 10)
else:
return below_20[n // 100 - 1] + " Hundred " + represent(n % 100)
# Initialize the result string
result = ""
# For each string in thousands
for t in thousands:
# If the last three digits are not zero
if num % 1000 != 0:
# Get the representation of the three-digit number, append result to it, and
# store it back in result
result = represent(num % 1000) + t + " " + result
# Divide num by 1000 and update num with the quotient
num //= 1000
# Return the result string
return result.strip()
def main():
nums = [0, 1, 12, 123, 1234, 12345, 123456, 1234567, 12345678, 123456789, 1234567890]
for i in range(len(nums)):
print(i + 1, ".\tnum: ", nums[i], sep = "")
print("\tWords:", number_to_words(nums[i]))
print("-"*100)
if __name__ == "__main__":
main()
Integer to English Words

Think about some other possible solutions, but now, let's move on to the next problem.

#4: Number of Islands#

In this problem, you’re given a 2D grid where each cell is either land (1) or water (0). Your task is to count the number of separate groups of land, or "islands," in the grid.

An island is a group of adjacent land cells connected either vertically or horizontally (not diagonally). Each island is surrounded by water or the edge of the grid.

The Union-Find approach helps identify and merge connected land areas (islands) within a grid. We iterate through each cell in the grid:

  • If a cell contains water (0), we skip it.

  • If it’s a land cell (1), we connect it with all adjacent land cells using the union operation, merging connected land into cohesive islands.

By marking visited cells and checking neighbors, this algorithm efficiently traverses the grid, identifying connected land regions. Finally, we count and return the total number of connected components, representing the number of islands in the grid.

canvasAnimation-image
1 / 25

You can dive deep into the solution of this problem at Number of Islands. This problem can also be solved using DFS and BFS, so think about it. For now, let's move to the next coding problem.

#5: Merge Sorted Array#

In this problem, you are given two arrays of numbers that are already sorted in ascending order, and two integers representing the number of elements in each array. Your task is to merge these two arrays into a single array that is also sorted in ascending order.

Assume the two arrays are nums1 and nums2. Then, nums1 has enough space at the end to hold all elements from nums2. Therefore, you need to merge nums2 into nums1 so that nums1 contains all the elements from both arrays in sorted order. At last just return nums1.

There are several optimized ways to solve this problem, one of which uses three pointers. Start by initializing two pointers at the last elements of each array and a third pointer at the last index of nums1. Traverse nums1 from the end, comparing the elements at the first two pointers. Place the larger value at the third pointer’s index and repeat until both arrays are merged.

You can explore this problem in detail including its solution at Merge Sorted Array.

#6: Lowest Common Ancestor of a Binary Tree#

In this problem, you are given the root of a binary tree and two nodes in that tree. Your task is to find those two nodes’ lowest common ancestor.

The lowest common ancestor (LCA) is the deepest node in the tree that is an ancestor of both nodes. In simpler terms, it's the closest common parent node of the two nodes you're looking at.

First, locate the two nodes in the tree (let’s call them p and q). Then, trace back up the tree to find the closest common ancestor of both nodes.

An intuitive way to traverse the tree is in a depth first manner. Explore the Lowest Common Ancestor in a Binary Tree problem to see how the algorithm works.

#7: Kth Largest Element in an Array#

In this problem, you are given an array of numbers and a number K. Your task is to find and return the Kth largest number in that list. Can you solve it without sorting?

Read the last sentence of the problem statement carefully—it provides a key hint. The straightforward solution is to sort the array in descending order and pick the Kth element, but the real challenge is finding the Kth largest element without sorting, as sorting takes O(n log n), which is inefficient for large arrays.

To solve this efficiently, use a min-heap of size K:

  1. Build a min-heap with the first K elements of the array.

  2. For each remaining element, if it’s larger than the smallest element in the heap (the root), replace the root with the current element and adjust the heap.

After processing all elements, the heap’s root will be the Kth largest element. This approach reduces the time complexity to O(n log k), where k is the size of the heap.

Look for as many hints as possible in the problem statement, as they guide you toward what the interviewer is looking for in the solution.

To get into details of this solution, check out Kth Largest Element in an Array.

#8: Longest Substring Without Repeating Characters#

In this problem, you are given a string, and your task is to return the length of the longest substringA substring is any sequence of characters that appears in the same order as they appear in the original string, without skipping any characters. without repeating characters.

The main challenge here is quickly finding the longest substrings with unique characters. One way to do this is to use a sliding window technique with two pointers and a hash set. Start with both pointers at the beginning of the string and a hash set to track characters within the current window.

  • If the characters pointed to by are not present in the set, add them to the set and expand the window by moving the right pointer.

  • If any character is already in the set, shrink the window from the left until the duplicate is removed.

Continuously update and keep track of the length of the longest substring without repeating characters as you adjust the window. Once the entire string is traversed, return this length.

Explore more about this problem at Longest Substring without Repeating Characters.

#9: Trapping Rain Water#

Imagine you have a series of bars of different heights, like a bar graph. After it rains, some of the rainwater can get trapped between these bars. Your task is to figure out how much rainwater is trapped.

Given a sequence of nonnegative integers representing the heights of bars in an elevation map, the goal is to determine the amount of rainwater that can be trapped between the bars after rain.

If the problem statement includes data that can be visualized, such as trees or graphs, draw them on paper to better understand the problem requirements.

To solve this problem, first calculate the maximum heights of the bars to the left and right of each bar.

For each bar, find the minimum of these two maximums. The water trapped above the bar is the difference between this minimum and the bar’s height. Summing up the trapped water across all bars gives the total rainwater trapped.

Now, let’s move to the next coding problem—our last one!

#10: Best Time to Buy and Sell Stock#

In this problem, you are given an array of prices for a stock, each for a different day.

Your task is to find the best day to buy and the best day to sell the stock to make the maximum profit. You can only make one buy and sell, and you must buy before selling.

To maximize profit from buying and selling stock, we need to find the maximum difference between two prices where the sell price is after the buy price.

A two-pointer approach works well here:

  1. Initialize a buy pointer at the beginning of the array and a sell pointer to iterate through the array.

  2. For each sell day, calculate profit by subtracting the buy price from the sell price. If this profit is higher than the current maximum, update the maximum profit.

  3. If a lower price is found, update the buy pointer to this new day.

Once the array is traversed, return the maximum profit.

Level up your skills and keep practicing#

If you're aiming for a role at a tech giant like MAANG, consistent practice is key! These companies are top-tier for a reason, and their interviewers are known for testing depth of knowledge.

Luckily, there are plenty of ways to prepare. Educative's learning paths, for example, cover frequently asked coding problems and offer a structured approach to interview prep. Working through these challenges can help you excel in technical interviews and beyond.

Keep exploring, practicing, and pushing your boundaries—you’ve got this! Happy learning!

Before you go, consider bookmarking these blogs:

Frequently Asked Questions

What are FAANG (MAANG) interview questions?

FAANG interview questions mix behavioral and technical aspects. On the technical side, they cover data structures: arrays, linked lists, trees, graphs, and hash tables; algorithms: sorting, searching, dynamic programming, and recursion; system design, designing scalable systems and understanding trade-offs; and coding challenges real-world problems that test your coding proficiency and analytical skills.

What language is used in FAANG (MAANG) coding interviews?

How to clear a FAANG (MAANG) interview?

Is a FAANG (MAANG) interview hard?

Which platform is best for FAANG (MAANG) preparation?


Written By:
Minahil Yaser
Join 2.5 million developers at
Explore the catalog

Free Resources