Arrays, Strings, And Matrix Fundamentals
Asked of: Machine Learning Engineer
Last updated

What's being tested
These prompts test linear-time array processing, two-pointer in-place mutation, matrix indexing, BFS pathfinding, and streaming window aggregates. For an MLE, the interviewer is probing whether you can write production-safe primitives for feature streams, batched tensors, ranking lists, and grid/state traversal with clear O(n) / O(mn) complexity.
Patterns & templates
-
Single-pass extrema tracking — for
maxProfit(prices), maintainmin_so_farandbest;O(n)time,O(1)space. -
Reverse two-pointer merge — for
merge(nums1, m, nums2, n), fill from the end to avoid overwriting; handle exhausted-array tails. -
Matrix diagonal traversal — compare
matrix[i][i]or anti-diagonalmatrix[i][cols-1-i]; validate rectangular shape and dimensions first. -
Bounds checking helper — centralize
0 <= r < rows and 0 <= c < cols; prevents repeated off-by-one bugs in grid logic. -
BFS for shortest path — use
deque,visited, andparentmap for path reconstruction;O(V+E)over grid cells. -
Sliding moving average — maintain
dequeplus runningsum; update inO(1)per event, avoiding recomputation over the full window. -
Sliding window order statistic — for median/min/max, use heaps, monotonic queues, or balanced trees; average alone only needs sum.
Common pitfalls
Pitfall: Treating empty arrays, single-element arrays, or all-decreasing stock prices as afterthoughts; define return values before coding.
Pitfall: Merging sorted arrays from the front in-place, which overwrites unprocessed values in
nums1.
Pitfall: Using DFS when the prompt asks for shortest path; BFS is the default for unweighted grid distances.
Practice these
The practice cards below cover the canonical variants — solve all of them and time yourself.
Featured in interview prep guides
Practice questions
- Find a String Containing AnotherMeta · Machine Learning Engineer · Technical Screen · medium
- Solve Two String ProblemsMeta · Machine Learning Engineer · Technical Screen · medium
- Merge two sorted arrays in-placeMeta · Machine Learning Engineer · Onsite · Medium
- Implement bounds, minimum, pathfinding, and moving averageMeta · Machine Learning Engineer · Onsite · Medium
- Maximize one stock trade profitMeta · Machine Learning Engineer · Onsite · Medium
- Check diagonal and compute window statisticsMeta · Machine Learning Engineer · Technical Screen · Medium
- Check diagonal equality in a matrixMeta · Machine Learning Engineer · Technical Screen · Medium
- Solve matrix diagonal and sliding-window statisticsMeta · Machine Learning Engineer · Technical Screen · Medium
Related concepts
- Array And String AlgorithmsCoding & Algorithms
- Arrays, Strings, Hash Maps, And Frequency CountingCoding & Algorithms
- Arrays, Strings, Hash Maps, And Sliding WindowsCoding & Algorithms
- Arrays, Intervals, Sliding Windows, And Prefix SumsCoding & Algorithms
- Arrays, Sliding Windows, DP And Stack PatternsCoding & Algorithms
- Array Search, Selection, And Dynamic ProgrammingCoding & Algorithms