TechSchool
Home / Interview questions / AI engineering / Meta

Meta AI Engineer Interview Questions

Short answers to 26 AI engineering questions asked at Meta.

Questions and answers (26)

Answers are written in plain English and reviewed for technical accuracy. Each answer states the point first, then the reason.

1. Given an array nums of n integers where n > 1, return an output array (product of array except self).

Use prefix and suffix products. Build a left array where left[i] is the product of all elements before i. Build a right running product and multiply it into the result. This uses O(n) time and O(1) extra space beyond the output.

res = [1] * n
for i in range(1, n):
    res[i] = res[i-1] * nums[i-1]
right = 1
for i in range(n-1, -1, -1):
    res[i] *= right
    right *= nums[i]

2. Find the minimum window in S which will contain all the characters in T.

Use a sliding window with two pointers and a character count map. Expand the right pointer until the window covers all of T. Then shrink the left pointer while the window stays valid. This runs in O(|S| + |T|) time.

need = Counter(t)
missing = len(t)
l = 0
for r, c in enumerate(s):
    missing -= need[c] > 0
    need[c] -= 1
    # shrink while missing == 0, then record the window

3. Serialize and deserialize a binary tree.

Use preorder traversal and mark null children with a sentinel. Write each node value and each sentinel into one string. Deserialize by reading tokens in the same order and rebuilding the tree. This costs O(n) time and O(n) space.

def ser(node):
    if not node: return 'N,'
    return str(node.val) + ',' + ser(node.left) + ser(node.right)
def de(tokens):
    v = next(tokens)
    if v == 'N': return None
    node = Node(int(v))
    node.left, node.right = de(tokens), de(tokens)
    return node

4. Convert a binary tree to a circular doubly linked list.

Do an in-order traversal and link each node to the previous node. Set the left pointer to the previous node and the right pointer to the next node. Then join the last node to the first node to close the circle. This uses O(n) time and O(1) extra space with Morris traversal.

prev = None
head = None
def walk(node):
    global prev, head
    if not node: return
    walk(node.left)
    if prev: prev.right, node.left = node, prev
    else: head = node
    prev = node
    walk(node.right)

5. Alien dictionary: determine character ordering from a sorted word list.

Compare each adjacent pair of words and take the first differing character as an edge. Run a topological sort on these edges to get the order. Return an empty string if the graph has a cycle. A word that is longer than its prefix neighbor makes the input invalid.

for w1, w2 in zip(words, words[1:]):
    if w1.startswith(w2) and len(w1) > len(w2): return ''
    for a, b in zip(w1, w2):
        if a != b:
            graph[a].add(b); indeg[b] += 1
            break

6. K closest points to origin; top-k frequent elements; minimum number of conference rooms.

Use a max-heap of size k for the k closest points and for the top-k frequent elements. Use a min-heap of end times for the conference rooms. The heap keeps memory at O(k) or O(rooms) instead of O(n). Each heap operation costs O(log k).

heap = []
for p in points:
    heappush(heap, (-dist(p), p))
    if len(heap) > k: heappop(heap)
# rooms: sort by start, push end times, pop when end <= start

7. Regular expression matching with '.' and '\*'.

Use dynamic programming with a table dp[i][j] for the first i characters of s and the first j of p. A star can match zero copies or one more copy of the previous character. This costs O(m*n) time and O(m*n) space.

dp[i][j] = dp[i-1][j-1] if s[i-1] == p[j-1] or p[j-1] == '.'
if p[j-1] == '*':
    dp[i][j] = dp[i][j-2]
    if s[i-1] == p[j-2] or p[j-2] == '.':
        dp[i][j] |= dp[i-1][j]

8. Two-part warm-up: given a stream of user actions, return the k most engaged-with items. Then: why might your heap solution be the wrong choice in production?

Keep a count map per item and a min-heap of size k keyed by count. This gives the top-k items in O(n log k) time. A heap is often wrong in production because counts change over time and a heap cannot update a key in place. Use a count-min sketch or a sorted set with O(1) updates instead.

for item in stream:
    cnt[item] = cnt.get(item, 0) + 1
    heappush(heap, (cnt[item], item))
    if len(heap) > k: heappop(heap)
# stale entries remain, so lazy deletion is required

9. Your ads CTR model shows a 2% offline AUC gain, but the online A/B is revenue-neutral with worse calibration. What is going on, and what do you do?

The offline AUC gain likely comes from a shift in ranking order that does not change revenue. AUC measures ranking over all users, but revenue depends on top slots and on calibrated click probabilities. A small AUC gain can come with worse calibration, so bid and value estimates become biased. Check calibration first with reliability curves and log loss on a time-based holdout. Then run the A/B test on the calibrated model and watch revenue per user, not AUC.

10. Explain the architectural choices in a Llama-class model: why grouped-query attention, RoPE and SwiGLU instead of the vanilla 2017 Transformer?

Llama-class models use grouped-query attention, RoPE and SwiGLU to cut cost and improve quality at long context. Grouped-query attention shares key and value heads across query heads, so the KV cache shrinks by the group factor. RoPE encodes position by rotating query and key vectors, so the model generalises to longer context without learned position tables. SwiGLU uses a gated feed-forward layer and gives better quality per FLOP than the vanilla ReLU block.

11. What breaks when you scale LLM training from 8 GPUs to thousands, and how do modern stacks deal with it?

At thousands of GPUs the main breaks are communication cost, hardware failures and loss instability. Data parallel all-reduce grows with cluster size, so stacks add tensor, pipeline and sequence parallelism. They also add sharded optimiser states, mixed precision and gradient checkpointing to fit memory. Failure handling uses fast checkpointing and elastic restart, because a node fails every few hours at this scale.

12. You need to serve a Llama-class 70B+ model to hundreds of millions of assistant users. What does the serving stack look like and where does the money go?

The stack has a router, a batched inference engine with paged attention, a KV cache tier and autoscaling replicas. The engine groups requests into batches and stores the KV cache in fixed pages, so memory does not fragment. Most of the money goes to GPU memory and compute for the KV cache and the decode step. Cost per token falls with larger batches, so batching and cache reuse are the main cost levers.

13. You're dropped into an unfamiliar multi-file codebase with a failing behaviour and an LLM assistant available. Walk me through how you'd fix it.

I first reproduce the failure with a small test and read the error trace. Then I ask the assistant to map the call path and list likely files, and I check each claim in the code. I make the smallest fix, run the test, and add a regression test. I keep the assistant on narrow tasks, because its file guesses are often wrong.

14. Walk me through a post-training recipe to turn a pretrained base model into a personalised assistant.

The recipe is supervised fine-tuning on assistant data, then preference tuning, then personalisation. Start with instruction data in the target style and run LoRA to keep cost low. Next use preference pairs with DPO or a reward model and PPO. Finally add per-user context or a small adapter per user segment, and evaluate with human raters and held-out tasks.

15. Design the recommendation system for Instagram Reels.

Reels ranking has a candidate generation stage, a light ranker and a heavy ranker with re-ranking. Candidate sources include follow graph, item-item similarity and trending pools. The ranker predicts watch time and completion, not just clicks, because short videos invite click bait. Re-ranking adds diversity, freshness and creator fairness, and the system serves from a feature store with tight latency budgets.

16. Design a personalised news-feed ranking system / the “next post” logic for Facebook's feed.

The feed ranker scores each candidate post with a multi-task model and then applies rules for diversity and freshness. Candidate sources include friends, groups, pages and ads. The model predicts several actions such as like, comment, share and hide, and combines them into one value score. A final pass removes near-duplicate posts and limits the same author, then the system logs the result for training.

17. Design a recommendation system for Facebook Ads, and an evaluation framework for ads ranking.

I split the system into candidate generation, ranking, and auction. A two-tower model retrieves a few thousand ads per user. A deep ranking model then scores them. The evaluation framework uses offline metrics like AUC and calibration, plus online A/B tests on revenue and user satisfaction. Offline gains do not always match online gains, so I gate each launch on a holdout experiment.

18. Design the ML components behind an Instagram Story feature.

The Story feature needs a ranking model, a media pipeline, and a safety classifier. The ranking model orders Stories by predicted watch time and skip rate. The media pipeline handles upload, transcoding, and preloading of the next Story. A safety classifier scans each upload before it reaches viewers.

19. Design an end-to-end classification pipeline for Marketplace listings.

The pipeline has four stages: ingestion, feature building, training, and serving. A gradient boosted tree model predicts whether a listing is spam, fraud, or policy violating. I use class weights because bad listings are rare. I track precision at a fixed recall, since false positives hurt good sellers.

20. Design a language translation model / service.

I build a sequence-to-sequence transformer with a shared tokenizer and train it on parallel text. The tokenizer splits text into subword units, which handles rare words and many languages. At serving time, I batch requests and use KV cache to avoid recomputing past tokens. A smaller distilled model can cut latency by about 50 percent with a small quality loss.

21. How would you build the evaluation system for a Meta AI assistant before and after each model release?

I build a fixed evaluation suite with golden prompts, human ratings, and safety checks. The suite runs before release on a frozen test set and after release on live traffic. I compare each model against the current production model on the same prompts. I also watch online metrics such as task success and report rate for two weeks.

22. Design the harmful-content detection system for Facebook and Instagram uploads.

The system uses a fast classifier on every upload and a slower model on flagged items. The fast model catches clear violations in milliseconds. The slower model reviews borderline cases with more context. I tune the threshold for high recall, then use human review to control precision.

23. How do modern multimodal models get image and video understanding into an LLM, and what changes for video specifically?

Multimodal models map images to tokens with a vision encoder and feed those tokens to the LLM. Video adds a time dimension, so the model needs temporal sampling and position encoding across frames. Video also costs far more tokens, so most systems sample a few frames per second. A 30 second clip at 1 frame per second gives 30 frames instead of one image.

24. Give me an example of a project where you used data and machine learning. What obstacles did you hit?

I built a churn model for a subscription product and hit two main obstacles. The first obstacle was label leakage from a field that was filled after cancellation. The second obstacle was a shift in user mix after a pricing change. I fixed the leakage by removing the field and added time-based validation, which dropped offline AUC by 0.08 but matched online results.

25. Tell me about a time you drove a significant result through ambiguity, and a time you were wrong.

I led a search ranking project when the goal was unclear. I wrote a one-page problem statement and agreed on one metric with the team. The first model missed the target by 20 percent. I was wrong about the feature set, so I removed the weak features and the next model passed the target.

26. Tell me about maintaining a production ML pipeline. Why Meta?

I kept a production ML pipeline healthy with daily data checks, model monitoring, and fast rollback. I added a check on input drift and it caught a broken upstream job in 10 minutes. Meta runs ML at large scale, so careful pipeline work has a direct effect on many users.

Related lessons
Ai agent intro Ai agent function calling Agent architecture Ai rag Retrieval augmented generation Vector database