Machine Learning Engineer Coding & Algorithms Interview Questions
Master your tech interview with our curated database of real questions from top companies.
Count subarrays summing to target
Question LeetCode 560. Subarray Sum Equals K – Given an integer array nums and an integer k, return the total number of continuous subarrays whose sum...
Solve matrix rotation and 1-D illumination
Question LeetCode 48. Rotate Image – rotate an n×n matrix 90° clockwise (extra space allowed). Find the point(s) with the maximum number of illuminate...
Find earliest supporting version under constraints
You are given version strings formatted as {major}.{minor}.{patch}, e.g., "103.003.03". Each version either supports a feature or not. You may call is...
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...
Solve meeting scheduling and robot cleaning tasks
You are given two independent coding problems. --- Problem 1: Prioritized Meeting Scheduling You are asked to schedule meetings in a single meeting ro...
Extend counter to per-client rate limiting
You are extending the recent-requests counter to support per-client rate limiting. Each request now includes a clientId identifying the caller. You mu...
Implement recent-requests counter
You are designing an in-memory component for a web service that needs to track how many requests ("hits") it has received in the last 5 minutes. Imple...
Generate all safe queen placements on board
You are given an integer n representing the size of a chessboard (n × n). You need to place n queens on the board so that no two queens attack each ot...
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,...
Design data structure similar to LRU cache
You are asked to design and implement a data structure that behaves similarly to an LRU (Least Recently Used) cache, but with a small variation: - The...
Rotate matrix and find max lamp coverage
1) Square-matrix rotation with extra space: Given an n x n integer matrix, return a new matrix that is the 90-degree clockwise rotation of the input. ...
Count connected delivery zones
Given an m x n grid representing a service area, each cell is either 'Z' (deliverable zone) or '#' (blocked). Two 'Z' cells belong to the same zone if...
Solve tree partition and IPO allocation
1) Tree partitioning for minimum difference: Given a rooted tree as an array parent of length n (parent[i] gives the parent of node i, and parent[root...
Validate palindrome with constraints
Given a string s, return true if s reads the same forward and backward after removing all non-alphanumeric characters and ignoring letter case. Implem...
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] ...
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. ...
Compute longest increasing subsequence
Given an integer array nums, compute the length of a longest strictly increasing subsequence and also output one valid subsequence. Aim for an O(n log...
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 ...
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...