DSA & Patterns
- Expect standard mediums in a sensor, perimeter or grid skin, graded on clarifying and working code over optimality
- Map a defense-skinned prompt to binary search on the answer, a monotonic stack or grid BFS by its trigger
- Drill each on a runnable problem (border-sensor range, warmer reading, nearest tower) with added edge cases and invalid input
Look for an Anduril tag on the usual practice sites and you won't find one. Don't read that as a sign the round is exotic. The problems are standard mediums, the kind any serious preparation already covers. They arrive dressed in the domain: towers along a border, readings off a field sensor, a route across a grid of obstacles. The prompt is written to be vague as well. So your first move is asking what the inputs really are. The pattern comes after.
The round runs in layers. You clarify and get something working. Then the interviewer starts adding: the arrays are uneven, an input is empty or malformed, an obstacle drops onto the path you just found. You don't have to finish every layer to advance. You aren't scored mainly on complexity, though a quadratic answer where a linear one was in reach still counts against you. This lesson names the three patterns that carry most of the bank and drills each one on a problem built to the domain.
How the coding bar is set
The phone screen is a shared editor, commonly two medium problems inside about an hour. The onsite adds two more coding sessions in the same collaborative style. Difficulty tops out at medium: the recurring named problems all sit at that level. Candidates who prepare with a standard medium set and the classic seventy-five arrive ready. What sets it apart from a generic screen is the delivery: each problem arrives one clarifying question and one added constraint at a time.
Expect the prompt to escalate on purpose. A sensor problem starts with clean, sorted positions. Next they're unsorted. Then some are duplicated, and then the tower list is empty and you have to decide what a sensible return even is. A pathfinding problem starts as a straight distance between two points, walls appear, and finally whole regions become unreachable. The interviewer is watching whether your first solution was written to bend. Code that hard-coded an assumption from the opening phrasing tends to snap when the second phase lands. Then you're rebuilding it against the clock, and that's the failure this format is built to catch.
The patterns that recur
Group the recurring problems by the machinery they need and three families cover most of them. Each has a signal in the wording and a default structure that goes with it. Once you've read the signal off the domain story and committed to the structure, the minutes you saved go to the boundaries the interviewer is about to probe.
Binary search on the answer
Some prompts ask for the smallest value that makes something feasible: the minimum range that covers every crossing, the minimum capacity that ships in time. There, the answer itself is what you binary search. Feasibility is monotone. If a sensor range of ten covers the whole border, so does eleven, and if eight fails, so does seven. So the feasible values form a sorted boundary, which is exactly what binary search finds. You write a predicate that asks "can we cover everything within this range?" Then you binary search for the smallest range where it flips from false to true. The recurring border-sensor problem is this pattern in defense clothing.
The monotonic stack
Sometimes each element waits for the next one that beats it: a warmer reading, a taller neighbor, a higher price. A plain double loop is quadratic there, and a stack is linear. Keep a stack of indices whose answer is still pending, ordered so their values only decrease from bottom to top. Each new element pops every pending index it exceeds, resolving them. An index is pushed once and popped once, so the whole scan is linear despite the inner loop. The signal is the phrase "next greater," or "how far until something larger." The defense skin is a stream of sensor readings asking how long until a stronger one.
Grid breadth-first search
When the input is a grid and the question is a distance to the nearest source, use breadth-first search. It expands one ring at a time, so the first time it reaches a cell, the step count it carries is the shortest. Internalize the multi-source version. Seed the queue with every source at once, every tower or every gate, and a single sweep fills each open cell with its distance to the closest one. Walls are cells the search refuses to enter. Any cell the sweep never reaches is unreachable, and that is often what the added phase is fishing for. Depth-first recursion is the wrong reach here, because it finds a path with no promise that it's shortest.
Each family announces itself through the domain story. A smallest-range-that-covers question is binary search on the answer: write the monotone feasibility predicate and search for where it flips. Wait-for-the-next-bigger questions are a monotonic stack, one push and one pop per element. A distance-to-nearest-source question on a grid is multi-source breadth-first search. The first arrival is the shortest distance, and cells never reached are the unreachable ones. Name the family from the wording before the skin distracts you. Then the interviewer's next escalation is a small edit instead of a rebuild.
Practice
Three problems, one per family, each modeled on the defense-skinned versions that show up on the real screen. The input is the function's arguments and the expected value is its return. Write the solution and run it against the cases. Then read the walkthrough. It carries the added-constraint follow-up the interviewer reaches for once the base case works.
Minimum Sensor Range Along a Border
Problem
crossings, the positions along that line that must be watched, and towers, the positions where detection towers are already placed. Every tower has the same sensor range r, and a tower covers a crossing when the distance between them is at most r.Return the minimum range
r such that every crossing is covered by at least one tower. Positions are integers and the answer is an integer. The lists are not necessarily sorted.If a crossing sits exactly on a tower, its distance is
0. You may assume there is at least one tower and at least one crossing.Input. Two arguments, the
crossings list and the towers list. Return an integer.Input: crossings = [1,5], towers = [2]
Output: 3
The single tower at position 2 sits distance 1 from the crossing at 1 and distance 3 from the crossing at 5. To cover both, the range must reach the farther one, so the minimum range is 3.
Feasibility is monotone in the range: if range r covers every crossing, so does any larger range. Write a predicate that asks whether a given range covers all crossings. Then binary search for the smallest range where it becomes true. The predicate checks each crossing against its nearest tower, found by binary search over the sorted towers.
Minimum Sensor Range Along a Border
Click "Run" to execute your code
Test Cases
[[1,2,3],[2]]Expected: 1[[1,2,3,4],[1,4]]Expected: 1[[1,5],[2]]Expected: 3[[10],[0]]Expected: 10[[5,5],[5]]Expected: 0[[1,2,3,4,5,6,7,8,9,10],[3,7]]Expected: 3[[1],[1,2,3]]Expected: 0[[-5,0,5],[0]]Expected: 5[[1,2,3,4,5],[1,5]]Expected: 2Days Until a Warmer Reading
Problem
temperatures. For each day, find how many days you must wait until a strictly warmer reading appears.Return a list
answer of the same length, where answer[i] is the number of days after day i until a warmer reading, or 0 if no later day is warmer.Input. One argument, the
temperatures list. Return a list of integers.Input: temperatures = [73,74,75,71,69,72,76,73]
Output: [1,1,4,2,1,1,0,0]
Day 0 at 73 is beaten the next day by 74, so 1. Day 2 at 75 isn't beaten until day 6 at 76, four days later, so 4. Days 6 and 7 never see a warmer reading, so both are 0.
Keep a stack of day indices whose warmer day is still pending, with their readings decreasing from bottom to top. When a new reading exceeds the reading at the top of the stack, that top day has found its warmer day: pop it and record the gap. Each index is pushed once and popped once, so the scan is linear.
Days Until a Warmer Reading
Click "Run" to execute your code
Test Cases
[[73,74,75,71,69,72,76,73]]Expected: [1,1,4,2,1,1,0,0][[30,40,50,60]]Expected: [1,1,1,0][[30,60,90]]Expected: [1,1,0][[90,80,70]]Expected: [0,0,0][[50]]Expected: [0][[50,50,50]]Expected: [0,0,0][[55,50,60,45,70]]Expected: [2,1,2,1,0][[71,71,72,70,72]]Expected: [2,1,0,1,0]Distance to the Nearest Tower
Problem
0 marks a detection tower, -1 marks an obstacle the signal cannot pass, and 2147483647 marks an open cell whose distance to the nearest tower is unknown.Fill every open cell with the number of steps to the nearest tower, moving only up, down, left, or right, and never through an obstacle. An open cell that no tower can reach keeps its value of
2147483647. Return the filled grid.Input. One argument, the
grid of integers. Return the grid with open cells filled in.Input: grid = [[2147483647,-1,0,2147483647],[2147483647,2147483647,2147483647,-1],[2147483647,-1,2147483647,-1],[0,-1,2147483647,2147483647]]
Output: [[3,-1,0,1],[2,2,1,-1],[1,-1,2,-1],[0,-1,3,4]]
A breadth-first sweep starts from both towers at once, and each open cell takes the fewest steps to whichever tower is closer. The open cell at the top left is three steps from the nearest tower, and every obstacle stays -1.
This is multi-source breadth-first search. Seed a queue with every tower cell at distance 0, then sweep outward. Each time you reach an open cell for the first time, its distance is one more than the cell you came from. Every source starts together, so the first arrival at any cell is its distance to the nearest tower.
Distance to the Nearest Tower
Click "Run" to execute your code
Test Cases
[[[2147483647,-1,0,2147483647],[2147483647,2147483647,2147483647,-1],[2147483647,-1,2147483647,-1],[0,-1,2147483647,2147483647]]]Expected: [[3,-1,0,1],[2,2,1,-1],[1,-1,2,-1],[0,-1,3,4]][[[2147483647,0],[2147483647,2147483647]]]Expected: [[1,0],[2,1]][[[0]]]Expected: [[0]][[[0,-1,2147483647]]]Expected: [[0,-1,2147483647]][[[2147483647,2147483647],[2147483647,2147483647]]]Expected: [[2147483647,2147483647],[2147483647,2147483647]][[[2147483647,-1,2147483647],[0,-1,2147483647]]]Expected: [[1,-1,2147483647],[0,-1,2147483647]][[[0,2147483647,2147483647,2147483647]]]Expected: [[0,1,2,3]][[[2147483647,2147483647],[0,2147483647]]]Expected: [[1,2],[0,1]]Key Takeaways
- ✓The coding round is standard medium problems in a defense skin, graded on a rhythm. Clarify a deliberately vague prompt, get a clean solution working, and hold up as the interviewer adds uneven arrays, invalid inputs and obstacles. Robustness is part of the answer.
- ✓Translate the story into the pattern in the first minute. A smallest-range-that-covers question is binary search on a monotone feasibility predicate. Wait-for-the-next-bigger questions take a monotonic stack of indices. A distance-to-nearest-source question on a grid is multi-source breadth-first search.
- ✓Write the base solution so it bends. A feasibility predicate lets the double-coverage escalation reuse the search. Storing indices lets the circular escalation reuse the stack. Seeding all sources at once lets the weighted-terrain escalation swap in a zero-one deque.
- ✓Complexity isn't the main scoring axis, but don't hand over a quadratic answer where a linear one was in reach. Name the family and cover the edge and invalid cases out loud. Treat the unreachable or degenerate input as the phase the interviewer is about to ask for.
Anduril interview guideKnow what Anduril asks before you walk in.
9 coding · 2 system design · 14 behavioral questions
Get their questions first.
InterviewLegend is independent and not affiliated with or endorsed by any company it covers.