Here are some of the top FAANG (Facebook, Amazon, Apple, Netflix, Google) interview questions for software engineering roles. These questions cover a variety of topics, including algorithms, data structures, system design, coding, and problem-solving.
Table of Contents
1. Array and String Questions
1.1. Find the Missing Number in an Array (1 to n)
Given an array of size n-1
containing distinct integers taken from the range 1
to n
. Find the missing number.
Example: Input: [1, 2, 4, 6, 3, 7, 8]
Output: 5
1.2. Reverse a String
Write a function to reverse a string in place.
Example: Input: "hello"
Output: "olleh"
1.3. Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters.
Example: Input: "abcabcbb"
Output: 3
(The answer is "abc"
which the length is 3
).
1.4. Merge Two Sorted Arrays
Given two sorted arrays, merge them into a single sorted array.
Example: Input: arr1 = [1, 3, 5]
, arr2 = [2, 4, 6]
Output: [1, 2, 3, 4, 5, 6]
2. Linked List Questions
2.1. Reverse a Linked List
Write a function to reverse a singly linked list.
Example: Input: 1 -> 2 -> 3 -> 4 -> null
Output: 4 -> 3 -> 2 -> 1 -> null
2.2. Detect a Cycle in a Linked List
Determine if a linked list has a cycle in it.
Example: Input: 1 -> 2 -> 3 -> 4 -> 2 (cycle)
Output: True
2.3. Merge Two Sorted Linked Lists
Given two sorted linked lists, merge them into one sorted linked list.
Example: Input: list1 = 1 -> 3 -> 5
, list2 = 2 -> 4 -> 6
Output: 1 -> 2 -> 3 -> 4 -> 5 -> 6
3. Tree and Graph Questions
3.1. Binary Tree Level Order Traversal
Given a binary tree, return the level order traversal of its nodes’ values.
3.2. Validate Binary Search Tree (BST)
Given a binary tree, check if it is a valid binary search tree (BST).
3.3. Find the Shortest Path in a Graph
Given a graph, find the shortest path between two nodes.
Example: Input: A graph with nodes [A, B, C, D]
and edges [A-B, A-C, C-D, B-D]
Output: Shortest path between A
and D
is [A, C, D]
.
4. Dynamic Programming Questions
4.1. Fibonacci Sequence
Write a function to return the n
th Fibonacci number.
Example: Input: n = 5
Output: 5
4.2. Longest Increasing Subsequence
Given an array of integers, return the length of the longest increasing subsequence.
Example: Input: [10, 9, 2, 5, 3, 7, 101, 18]
Output: 4
(The longest increasing subsequence is [2, 3, 7, 101]
).
4.3. Coin Change Problem
Given coins of different denominations and a total amount, find the minimum number of coins needed to make up that amount.
Example: Input: coins = [1, 2, 5]
, amount = 11
Output: 3
(The optimal solution is to use two 5’s and one 1).
5. Sorting and Searching Questions
5.1. Binary Search
Implement binary search to find an element in a sorted array.
Example: Input: arr = [1, 3, 5, 7, 9]
, target = 5
Output: 2
5.2. Kth Largest Element in an Array
Find the k
th largest element in an unsorted array.
Example: Input: arr = [3, 2, 1, 5, 6, 4]
, k = 2
Output: 5
5.3. Merge Sort
Implement the merge sort algorithm.
Example: Input: [5, 3, 8, 6, 2]
Output: [2, 3, 5, 6, 8]
6. System Design Questions
6.1. Design a URL Shortener (e.g., bit.ly)
Design a system that takes a long URL and returns a short URL. It should be able to map the short URL back to the original URL.
6.2. Design a Rate Limiter
Design a rate limiter that allows a maximum of N
requests per minute. Implement the solution that handles edge cases like burst traffic.
6.3. Design a Twitter-like System
Design a system that mimics a simplified version of Twitter. The system should handle following users, posting tweets, and displaying a user’s timeline.
7. Concurrency Questions
7.1. Implement a Thread Pool
Design a thread pool to manage multiple threads efficiently.
7.2. Implement a Producer-Consumer Problem
Solve the producer-consumer problem using synchronization methods (locks, semaphores, etc.).
8. Miscellaneous Questions
8.1. Find Duplicate in Array
Given an array of integers, find the duplicate element (assuming there’s exactly one duplicate).
Example: Input: [1, 3, 4, 2, 2]
Output: 2
8.2. Find the Intersection of Two Arrays
Find the intersection of two arrays, where each element in the intersection appears as many times as it appears in both arrays.
Example: Input: nums1 = [1, 2, 2, 1]
, nums2 = [2, 2]
Output: [2, 2]
8.3. Rotate Matrix
Given an n x n
matrix, rotate it 90 degrees clockwise.
Example: Input:
[ [1, 2, 3],
[4, 5, 6],
[7, 8, 9] ]
Output:
[ [7, 4, 1],
[8, 5, 2],
[9, 6, 3] ]