Skip to content

Meta (Facebook) Coding Questions 2025 - Interview Problems with Solutions

Meta coding interview questions with solutions in Python and Java. Practice DSA problems asked in Meta E3/E4/E5 interviews 2025.

Meta Coding Questions - Complete Problem Set

Section titled “Meta Coding Questions - Complete Problem Set”

Practice 25+ Meta coding interview questions with solutions. Meta focuses on optimal solutions, clean code, and problem-solving speed.

Find total number of subarrays with sum equal to k.

Input: nums = [1,1,1], k = 2
Output: 2

Find minimum window in s containing all characters of t.

Input: s = “ADOBECODEBANC”, t = “ABC”
Output: “BANC”

Check if string can become palindrome by removing at most one character.

Input: “abca”
Output: true (remove ‘c’ or ‘b’)

Merge overlapping intervals.

Input: [[1,3],[2,6],[8,10],[15,18]]
Output: [[1,6],[8,10],[15,18]]

Pick index randomly with probability proportional to weight.

Return vertical order traversal of binary tree.

Deep clone a graph.

def diameter_of_binary_tree(root):
diameter = 0
def dfs(node):
nonlocal diameter
if not node:
return 0
left = dfs(node.left)
right = dfs(node.right)
diameter = max(diameter, left + right)
return max(left, right) + 1
dfs(root)
return diameter

Find LCA where p or q may not exist in tree.

Find order of characters in alien language.

Check if array has continuous subarray of size >= 2 with sum multiple of k.

Count ways to decode number string to letters.

Input: “226”
Output: 3 (“BZ”, “VF”, “BBF”)

class NumMatrix:
def __init__(self, matrix):
self.matrix = matrix
self.m, self.n = len(matrix), len(matrix[0])
self.prefix = [[0] * (self.n + 1) for _ in range(self.m + 1)]
self._build_prefix()
def _build_prefix(self):
for i in range(self.m):
for j in range(self.n):
self.prefix[i+1][j+1] = (self.matrix[i][j] +
self.prefix[i][j+1] +
self.prefix[i+1][j] -
self.prefix[i][j])
def sumRegion(self, r1, c1, r2, c2):
return (self.prefix[r2+1][c2+1] - self.prefix[r1][c2+1] -
self.prefix[r2+1][c1] + self.prefix[r1][c1])

14. Design Add and Search Words Data Structure

Section titled “14. Design Add and Search Words Data Structure”
class WordDictionary:
def __init__(self):
self.root = {}
def addWord(self, word):
node = self.root
for char in word:
if char not in node:
node[char] = {}
node = node[char]
node['#'] = True
def search(self, word):
def dfs(node, i):
if i == len(word):
return '#' in node
if word[i] == '.':
for child in node:
if child != '#' and dfs(node[child], i + 1):
return True
return False
else:
if word[i] not in node:
return False
return dfs(node[word[i]], i + 1)
return dfs(self.root, 0)
from collections import OrderedDict
class LRUCache:
def __init__(self, capacity):
self.cache = OrderedDict()
self.capacity = capacity
def get(self, key):
if key not in self.cache:
return -1
self.cache.move_to_end(key)
return self.cache[key]
def put(self, key, value):
if key in self.cache:
self.cache.move_to_end(key)
self.cache[key] = value
if len(self.cache) > self.capacity:
self.cache.popitem(last=False)

Find buildings with ocean view (no taller building to the right).

def depth_sum(nested_list):
def dfs(nested, depth):
total = 0
for item in nested:
if isinstance(item, int):
total += item * depth
else:
total += dfs(item, depth + 1)
return total
return dfs(nested_list, 1)
from collections import deque
class MovingAverage:
def __init__(self, size):
self.size = size
self.queue = deque()
self.window_sum = 0
def next(self, val):
self.queue.append(val)
self.window_sum += val
if len(self.queue) > self.size:
self.window_sum -= self.queue.popleft()
return self.window_sum / len(self.queue)

Meta Preparation Guide

Complete preparation strategy. View Guide →


Practice these problems for Meta interviews!

Last updated: February 2026