Amazon Machine Learning Engineer Coding & Algorithms Interview Questions
Practice the exact questions companies are asking right now.
Find shortest transformation steps in a word graph
You are given two strings begin and end of the same length, and a list words of distinct strings (also same length). You can transform one string into...
Implement K-means and solve interval/frequency tasks
Task 1 — Describe/implement K-means clustering Given: - A data matrix X with shape (n_samples, d). - An integer k (number of clusters). Explain (or wr...
Implement PyTorch training loop
Implement a basic PyTorch training loop You are given a PyTorch neural network model, a DataLoader that yields (inputs, targets) batches, an optimizer...
Find shortest path in a grid with obstacles
You are given a 2D grid of size m x n representing a maze. Each cell in the grid is either empty (0) or blocked (1). You are also given two coordinate...
Implement integer division without using division
You are given two 32-bit signed integers dividend and divisor. Implement a function that divides dividend by divisor and returns the integer quotient,...
Find two numbers that sum to target
Given an integer array nums of length n and an integer target, return the indices (i, j) (0-based) of two distinct elements such that nums[i] + nums[j...
Implement decoder-only GPT-style transformer
Goal Implement a simplified decoder-only Transformer language model (similar in spirit to GPT) for next-token prediction. The implementation should be...
Design LFU cache with distributed extension
Problem You are asked to design and implement a data structure that behaves like an in-memory cache with a Least Frequently Used (LFU) eviction policy...
Check if adding edge creates cycle in digraph
You work with a system that stores items and directed relationships between them (for example, item A points to item B). The relationships form a dire...
Implement binary search lower/upper bounds
Given a non-decreasing sorted array nums and a target value, implement two functions using binary search: ( 1) lower_bound(nums, target) that returns ...
Implement lower_bound and upper_bound binary search
Implement two functions for a nondecreasing sorted integer array nums of length n: lower_bound(target) returns the smallest index i such that nums[i] ...
Implement inventory allocation with backorders
Design and implement a function to process an event stream for an e-commerce marketplace. Input: ( 1) initial inventory as a list of (sku: string, qty...