Meta Machine Learning Engineer Coding & Algorithms Interview Questions
Practice the exact questions companies are asking right now.
Implement weighted random city and sparse dot product
Question 1: Weighted random city picker You are given a mapping from city → population (all populations are positive integers). Implement a random gen...
Compute nested depth sum and grid distance
Problem A: Weighted sum of integers in a nested list You are given a nested list structure that may contain integers or other nested lists. Define the...
Solve shipping capacity and expression insertion
Problem A: Minimum shipping capacity You are given an array weights where weights[i] is the weight of the i-th package. Packages must be shipped in or...
Solve linked list, tree, and grid problems
Problem A — Find cycle entry in a singly linked list You are given the head of a singly linked list. The list may contain a cycle. - Return the node w...
Solve two linked list/array tasks
You are given two independent coding tasks. Task 1: Remove the N-th node from the end of a singly linked list Given the head of a singly linked list a...
Solve array merge, tree view, and maze tasks
Solve the following coding tasks. 1) Merge two sorted arrays in-place You are given two integer arrays A and B, each sorted in non-decreasing order. -...
Find longest palindromic substring
Given a string s, return the longest contiguous substring of s that is a palindrome. Input - A single string s. Output - A string representing the lon...
Optimize repeated-value vectors and compute exclusive times
You are given two separate coding tasks from an interview. Task 1: Optimize storage for vectors with repeated values, then compute dot product You are...
Find target using robot movement API
You control a robot in an unknown 2D grid. The grid layout and boundaries are unknown, and you cannot access the map directly. Some cells are blocked ...
Compute binary tree left-side view
Given a binary tree, return the values visible from the left side when looking from top to bottom. If multiple nodes exist at the same depth, the left...
Detect cycles and order with DFS
You are given a directed graph of package dependencies represented as an adjacency list: Map<String, List<String>> deps where deps[p] lists packages t...
Maximize one stock trade profit
You're given an array prices of length n where prices[i] is the stock price on day i. You may complete at most one transaction (buy once, then sell la...
Find kth smallest pair sum with heaps
You are given two nondecreasing arrays A (length n) and B (length m) of non-negative integers and an integer k (1 <= k <= n*m). Return the k-th smalle...
Optimize ribbon piece length by binary search
Given an array lengths of positive integers and an integer k, you may cut each element into pieces of integer length L > 0. Find the maximum L such th...
Generate unique permutations with duplicates
Given an array of integers that may contain duplicates, generate all unique permutations. Ensure no duplicate permutations are returned even if some v...
Return k smallest elements using heap
Given an unsorted array nums of up to 1,000,000 integers and an integer k (1 <= k <= nums.length), return the k smallest elements in ascending order. ...
Find connected region sizes in matrix
Given an m x n grid of characters grid and a target character ch, implement: ( 1) sizeOfRegion(grid, r0, c0, ch) -> int that returns the size of the 4...
Implement bounds, minimum, pathfinding, and moving average
Solve the following data-structures problems: ( 1) Given two sorted integer lists A and B, merge them into a single non-decreasing array. Then, for a ...
Merge two sorted arrays in-place
You are given two nondecreasing arrays A and B, where A has enough trailing empty slots to hold all elements of B. Merge B into A in-place so that A r...
Implement exponentiation and link tree neighbors
Solve two independent tasks. Task A — Fast exponentiation: Implement fastExponent(x, n) that returns x raised to the integer power n, where x is a dou...