TechSchool
Home / Interview questions / AI engineering / Amazon

Amazon AI Engineer Interview Questions

Short answers to 23 AI engineering questions asked at Amazon.

Questions and answers (23)

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

1. Find the top-K most frequent items in a high-volume event stream with bounded memory.

Use a count-min sketch with a min-heap of size K. The sketch stores approximate counts in fixed memory. The heap keeps the current top-K candidates. A width of 10000 counters gives small error for most streams.

sketch = CountMin(width=10000, depth=5)
heap = MinHeap()
for x in stream:
    c = sketch.add(x)
    if c > heap.min():
        heap.push(x, c)

2. Divide two integers without using multiplication, division or modulo. Find the number of connected components in a graph. Check balanced parentheses.

Use bit shifts to subtract the largest shifted divisor. Use a visited set to count connected components. Use a stack to check balanced parentheses. Each method runs in O(n) or O(log n) time.

def divide(a, b):
    q = 0
    while a >= b:
        s, d = 0, b
        while a >= (d << 1): d <<= 1; s += 1
        a -= d; q += 1 << s
    return q

3. What is the closed-form solution of linear regression, and when do you use gradient descent instead?

The closed-form solution is w = (X^T X)^(-1) X^T y. Use gradient descent when the feature count is large or X^T X is singular. Inverting a d-by-d matrix costs about d^3 FLOPs. Gradient descent costs about n times d FLOPs per step.

4. What are the differences between L1 and L2 regularization in logistic regression?

L1 adds the sum of absolute weights to the loss. L2 adds the sum of squared weights. L1 drives some weights to exactly zero and gives sparse models. L2 shrinks all weights smoothly and handles correlated features better.

5. Write the loss function for logistic regression and prove it has a global minimum.

The loss is L(w) = -sum over i of [y_i log p_i + (1 - y_i) log(1 - p_i)]. This loss is convex in w, so every local minimum is a global minimum. The Hessian X^T D X is positive semidefinite, where D holds p_i(1 - p_i).

6. How is KL divergence loss different from cross-entropy loss? And from contrastive loss?

KL divergence measures the extra cost of using an approximate distribution instead of the true one. Cross-entropy equals KL divergence plus the entropy of the true distribution. The entropy term is constant during training, so the two losses give the same gradient. Contrastive loss pulls similar pairs together and pushes different pairs apart.

7. How do bagging and boosting differ? What is the computational difference between XGBoost and Random Forest?

Bagging trains models in parallel on bootstrap samples and averages them. Boosting trains models in sequence, and each model fixes the errors of the last one. Random Forest builds many deep trees in parallel. XGBoost builds shallow trees in sequence and costs more per tree because it computes gradients and Hessians.

8. Explain the bias-variance trade-off, cross-validation, and the curse of dimensionality.

The bias-variance trade-off balances underfitting against overfitting. Cross-validation estimates test error by training on K-1 folds and testing on the held-out fold. The curse of dimensionality means distances lose meaning as dimensions grow. At 100 dimensions, most points sit near the edge of the space.

9. How do GRU cells work, and how do they address the vanishing gradient problem? How does a BiLSTM work?

A GRU cell uses an update gate and a reset gate to control the hidden state. The update gate keeps old information, so gradients flow over many steps and decay less. A BiLSTM runs one LSTM forward and one LSTM backward, then joins both outputs. This gives each position context from the left and the right.

10. What is Attention in machine learning models? What happens in a neural network if you remove all the hidden layers?

Attention lets a model weight each input part by its relevance to the current query. It computes scores, turns them into weights, and takes a weighted sum of values. If you remove all hidden layers, the network becomes a single linear map. It can then learn only linear functions and cannot model curved decision boundaries.

11. Discuss precision, recall and F1: when would you prioritise one over the others?

Precision measures correct positives among predicted positives, and recall measures correct positives among real positives. F1 is their harmonic mean. Prioritise recall when a missed positive is costly, such as cancer screening. Prioritise precision when a false alarm is costly, such as spam blocking.

12. How do you handle data imbalance, collinearity, feature selection and regularization?

Handle imbalance with resampling or class weights, and handle collinearity by dropping or merging correlated features. Select features by filter, wrapper, or embedded methods. Use L1 regularization for sparse weights and L2 for small smooth weights. Tune the regularization strength on a validation set.

13. Explain how you would design and evaluate an A/B test. What is a p-value and how do you interpret it here?

Randomize users into control and treatment groups, then compare one primary metric with a fixed sample size. A p-value is the chance of seeing this result, or a more extreme one, if the null hypothesis is true. A p-value of 0.03 means a 3 percent chance under the null. It does not give the chance that the treatment works.

14. What is Maximum Likelihood Estimation and how does it differ from Bayesian inference?

Maximum Likelihood Estimation picks the parameter values that make the observed data most probable. Bayesian inference starts with a prior and updates it to a posterior with Bayes rule. MLE gives one point estimate, while Bayesian inference gives a full distribution. The posterior mean equals the MLE when the prior is flat.

15. Why did transformers displace RNNs for language modelling, and what exactly does the KV cache buy you at inference time?

Transformers displaced RNNs because attention processes all tokens in parallel and captures long-range links directly. The KV cache stores past key and value tensors, so each new token avoids recomputing them. This cuts per-step work from quadratic to linear in sequence length. The cost is extra memory that grows with context length.

16. A customer's Bedrock-hosted workload costs too much. Cut inference cost dramatically without unacceptable quality loss.

Cut cost with smaller models, prompt caching, shorter prompts, and batching, then check quality on a fixed eval set. Route easy requests to a cheap model and hard requests to a strong model. Use prompt caching to skip repeated prefix work. Accept a small quality drop only when the eval shows it stays within a set threshold.

17. Design an agent that operates a web browser to complete multi-step tasks. How do you make it reliable enough to ship?

Make the browser agent reliable with a plan-act-check loop and a hard sandbox. The agent writes each step as a small action, then checks the page state before the next step. Add retries, timeouts, and a human handoff for login or payment pages. Log every action so you can replay failures.

18. Design a multi-tenant inference platform that serves many foundation models to thousands of customers (Bedrock-shaped).

Split the platform into a control plane and a data plane. The control plane handles tenants, quotas, and model routing. The data plane runs paged attention with a shared KV cache and per-tenant limits. Isolate each tenant with separate queues and rate limits.

19. How would you design a recommendation system to suggest books to users? How would you model a warehouse inventory problem?

For books, use a two-stage recommender. A candidate generator pulls similar books from embeddings, then a ranker scores them with user history. For warehouse inventory, model it as a forecast plus a reorder policy. Set the reorder point from demand variance and lead time.

20. How would you decide an LLM-powered assistant is ready to launch to millions of customers?

Launch only after offline evals, online shadow tests, and a staged rollout pass clear gates. Track task success, hallucination rate, and cost per request. Start with 1 percent of traffic and expand only if metrics hold. Keep a kill switch and a fallback model ready.

21. Tell me about a time you disagreed with your team's technical direction. What did you do? (Have Backbone; Disagree and Commit)

I once disagreed with my team on adding a cache layer before launch. I wrote a short doc with latency numbers and a risk list. The team chose a smaller cache scope, and I committed fully. The launch met its date and we added the rest later.

22. Tell me about your most significant failure. What happened, and what did you change afterward?

My biggest failure was shipping a model without a proper eval set. It passed demos but failed on real user queries. I changed my process to require a held-out eval set before any release. I also added a rollback plan to every launch.

23. Tell me about a time you saw an opportunity to do something bigger than the initial scope. (Think Big)

I saw that our internal eval tool can help other teams. I proposed a shared service with an API. I built a small prototype and showed the time savings. The team adopted it and it became a company-wide tool.

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