Algorithms & Simulation
- Expect in-house, implementation-heavy problems graded on hidden tests and inputs where brute force times out
- Name the three archetypes the assessment reskins and the data structure each one wants
- Drill a comment stripper, axis-aligned squares and a multi-source BFS grid, each built from an HRT problem
Most firms build a coding screen by sampling the LeetCode canon. A two-sum here, a graph clone there: problems you recognize on sight because thousands of people have solved the exact same ones. Hudson River Trading does not do that. The online assessment is a set of problems written in-house, dressed in specific mechanics, and tuned so that the obvious quadratic solution runs out of time on the hidden inputs. Almost nothing on an HRT set has a standard name you could look up, and that is by design.
That sounds harder than it is. The stories are original, but the machinery underneath is a small, stable set of shapes. Read enough of the real prompts and three keep returning. One is a stateful pass over a stream of characters or events. Another is a counting question over a set of Cartesian points. The third is a traversal over a grid. Learn to see the shape through the costume and the assessment stops being a series of surprises. It becomes three techniques you already own, applied under a clock, with edge cases that decide the verdict.
How HRT frames the assessment
The first gate for interns, new grads, and experienced engineers alike is a timed online assessment. It is typically two to four problems in a seventy-five to one-hundred-fifty minute window, on whichever platform the cycle uses. C++ and Python are both accepted, and C++ is the safe default for the software-engineer and core tracks. The set escalates in difficulty: an easy warm-up or two, an implementation-heavy middle, and a hard capstone that needs the right complexity rather than the first idea that compiles.
Two properties of the grading matter more than the problem text. First, the inputs are large on purpose, so a brute-force scan that is correct on the samples still fails the timed hidden cases. A geometry problem with a hundred thousand points wants a solution that is near-linear or n-log-n, not one that checks every quadruple. Second, passing every visible test does not mean you advance. The hidden battery probes the corners: the empty input, the single element, the value that sits exactly on a boundary. Engineers have gone one hundred percent green on the samples and still been cut because a corner case failed silently.
The three archetypes
Sort the real prompts by machinery and they collapse into three families. Each has a tell in the problem statement and a default structure that fits it. Spot the family first, reach for its structure, then spend your remaining time on the corners.
Archetype 1: Stateful simulation and parsing
A problem hands you a stream, a run of characters or a sequence of commands, and asks for the result of walking it once while a small amount of state changes underneath. HRT reaches for this shape often: a one-line text editor that consumes keystrokes in command and insert modes, and a source-code length calculator that counts real code while skipping comments. The default here is a single left-to-right pass with an explicit state variable. Decide the handful of states the stream can be in, decide what each input does in each state, and never scan the input twice. The trap is trying to strip or transform the stream with clever slicing instead of walking it character by character with a mode you can name.
Archetype 2: Counting and geometry over a point set
A problem gives you a list of integer coordinates and asks how many shapes they form, squares, then rectangles, or how many points cluster within a small distance of each other. The naive answer enumerates every triple or quadruple of points, which is cubic or worse and dies on the large input. The default that works is a hash set of the points for constant-time membership. Then enumerate a smaller structure, such as pairs of points that could be a diagonal or a shared side, and use the set to test for the corners that complete the shape. The whole skill is dropping the enumeration by one order: from every quadruple to every pair, with the set doing the rest.
Archetype 3: Grid traversal
A problem lays out a two-dimensional board with cells that are open, blocked, or seeded, and asks how something spreads, how far the farthest cell is, or whether every cell can be reached. It is breadth-first search on a grid, and multi-source BFS when several cells start active at once. Push every seed into the queue at distance zero and let them expand together, so the distance you record for each cell is already its distance to the nearest seed. The reachability answer falls out of the same pass, since any open cell the queue never touches is unreachable. Depth-first recursion is the tempting alternative and the wrong one, because it gives you connectivity but not the shortest spread distance.
The assessment is bespoke on the surface and predictable underneath. A parsing problem wants one pass with a named state, never a second scan. A point-set problem wants a hash set plus an enumeration one order smaller than the brute force, pairs instead of quadruples. A grid problem wants multi-source BFS, every seed enqueued at distance zero so nearest-seed distance and reachability both come free. Read the statement, match it to one of the three, and the large-input constraint that would sink a brute force is exactly what your structure was chosen to survive.
Asked at Hudson River Trading
Three problems, one per archetype, each a faithful reskin of an HRT assessment problem. They use the plain function format: the input is the function's arguments and the expected value is its return. Write the solution in the editor, run it against the hidden-style cases, then read the walkthrough, which carries the realistic escalation the rest of the way.
Source Length Without Comments
Problem
Two comment forms exist, following C and C++ rules:
- A line comment starts at
// and runs to the end of that line. The terminating newline is not part of the comment.- A block comment starts at
/* and runs until the first following */. Block comments do not nest, so the first */ closes the comment no matter how many /* appeared inside it. A block comment may span multiple lines.Everything outside a comment counts if it is not whitespace. Whitespace means spaces, tabs, and newlines. A
/ that is not the start of // or /* is an ordinary character and counts, for example the divide in a/b.Return the number of non-whitespace code characters.
Input. One argument, the source string. Return an integer.
Input: source = "int a = 1; // set a\nint b = 2;"
Output: 14
The two statements contribute seven non-whitespace characters each, i, n, t, a, =, 1, ; and i, n, t, b, =, 2, ; while the line comment and the newline are ignored.
Walk the string once with a mode variable that is one of code, line-comment, or block-comment. In code mode, look one character ahead to detect the start of a comment; otherwise count the character if it is not whitespace. In a comment mode, only watch for the token that ends it.
Source Length Without Comments
Click "Run" to execute your code
Test Cases
["int a = 1; // set a\nint b = 2;"]Expected: 14["a/* b */c"]Expected: 2["x /* multi\nline */ y"]Expected: 2["a/b"]Expected: 3["/* /* still one */ z"]Expected: 1["ok//trailing"]Expected: 2["//just comment"]Expected: 0[""]Expected: 0[" \t\n "]Expected: 0["f(x); /* note */ g(y); // done\nh();"]Expected: 14// that lives inside a block comment, or a */ that appears inside a line comment and means nothing. Name the three modes, decide what each character does in each mode, and the tricky overlaps resolve themselves.// or /* inside a double-quoted string is not a comment. So the parser needs a fourth mode for being inside a string. You enter it on an unescaped quote and leave on the next unescaped quote, and a backslash escapes the character after it. Inside a string, characters count as code. The walkthrough shows the extra mode and why the escape handling has to sit in exactly one place.Axis-Aligned Squares From a Point Set
Problem
An axis-aligned square has its sides parallel to the axes. Its four corners are
(x1, y1), (x1, y2), (x2, y1), (x2, y2) where the horizontal and vertical extents are equal and non-zero, that is x1 != x2 and abs(x1 - x2) == abs(y1 - y2). Tilted squares do not count.The input can be large, so an approach that inspects every group of four points is too slow. Return the number of such squares.
Input. One argument, a list of
[x, y] integer pairs. Return an integer.Input: points = [[0,0],[0,1],[1,0],[1,1]]
Output: 1
The four points are the corners of the unit square, so the count is one.
Load the points into a hash set for constant-time lookup. Enumerate unordered pairs of points and treat each pair as a possible diagonal of a square: it qualifies when the x and y gaps are equal and non-zero. Complete the square by testing the two off-diagonal corners in the set. Each square is found by both of its diagonals, so divide the total by two.
Axis-Aligned Squares From a Point Set
Click "Run" to execute your code
Test Cases
[[[0,0],[0,1],[1,0],[1,1]]]Expected: 1[[[0,0],[0,1],[0,2],[1,0],[1,1],[1,2],[2,0],[2,1],[2,2]]]Expected: 5[[[0,0],[0,1],[1,0]]]Expected: 0[[[0,0],[0,2],[2,0],[2,2],[1,1]]]Expected: 1[[[0,0],[0,1],[1,0],[1,1],[1,2],[0,2]]]Expected: 2[[[5,5]]]Expected: 0[[[0,0],[3,0],[0,3],[3,3],[0,1],[1,0],[1,1]]]Expected: 2[[[-1,-1],[-1,1],[1,-1],[1,1]]]Expected: 1Spreading Failure Across a Grid
Problem
-
1, a machine that has already failed at the start.-
0, a healthy machine.-
2, an empty rack slot that nothing passes through.Every tick, failure spreads from each failed machine to the healthy machines directly above, below, left, and right of it. Empty slots block the spread and are never healthy machines.
Return the number of ticks until every healthy machine has failed. If some healthy machine can never be reached, return
-1. If there are no healthy machines to begin with, return 0.Input. One argument, the grid as a list of lists of integers. Return an integer.
Input: grid = [[1,0,0],[0,0,0],[0,0,1]]
Output: 2
Failure starts at two opposite corners and spreads inward. The last healthy machines to fail are two ticks from the nearest failure, so the answer is two.
Push every starting failure into a queue at distance zero and run breadth-first search outward together. The distance recorded when a healthy machine is first reached is its distance to the nearest failure, and the answer is the largest such distance. Count the healthy cells first; if the search reaches fewer than that, some cell is walled off, so return -1.
Spreading Failure Across a Grid
Click "Run" to execute your code
Test Cases
[[[1,0,0],[0,0,0],[0,0,1]]]Expected: 2[[[1,1],[1,1]]]Expected: 0[[[1,2,0]]]Expected: -1[[[1,0,0,0]]]Expected: 3[[[0,0]]]Expected: -1[[[1,0],[2,0]]]Expected: 2[[[2,2,2]]]Expected: 0[[[1,0,2],[2,0,2],[2,0,1]]]Expected: 2Key Takeaways
- ✓HRT writes its own assessment problems rather than sampling the LeetCode canon, so recognition of named questions does not help and there is nothing to look up. The leverage is spotting the archetype under the bespoke story, then applying the structure that fits the constraint sizes.
- ✓Three archetypes cover the recurring sets. Stateful simulation and parsing take a single pass and a named mode. Counting and geometry over a point set take a hash set and pair enumeration. Grid traversal takes multi-source BFS.
- ✓The grading is built to defeat brute force. Inputs are large enough that a quartic point-set scan or a repeated per-source search times out. Hidden cases probe the boundaries, so a solution that passes every visible test can still be cut on a corner it never handled.
- ✓Each drill hides a realistic escalation: string literals turn the comment stripper into a fourth mode, rectangles relax the square test to any slanted diagonal, and diagonal spread swaps four neighbor offsets for eight. Solve the base shape cleanly and the escalation is a small, named change.
Hudson River Trading interview guideKnow what Hudson River Trading asks before you walk in.
7 coding · 1 system design · 16 behavioral questions
Get their questions first.
InterviewLegend is independent and not affiliated with or endorsed by any company it covers.