Catch Fish with Reusable Baits
Reported by candidates from Hudson River Trading's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The Hudson River Trading OA reported in September 2026 looks like a fishing story, but it's a greedy matching problem with a cap of three uses per bait. You sort both arrays, then simulate exactly what the statement says. Largest bait goes first, and it grabs the largest fish it can legally catch. If you're taking this in a day or two, the real work is getting the data structure and the strictly-smaller check right. StealthCoder sits invisibly on your screen as a safety net if you blank mid-assessment, but this one is very doable once you see the shape.
The problem
You are given two arrays of positive integers, fish and baits. Each value in fish is a fish size, and each value in baits is the size of one bait. A bait can catch a fish only when the bait is strictly smaller than that fish. A caught fish is removed and cannot be caught again. Each bait can be used at most 3 times. Process the baits from largest to smallest. For each bait, repeatedly catch the largest remaining fish that it can catch. Move to the next bait after the current bait has been used three times or when it cannot catch any remaining fish. Return the total number of caught fish after every bait has been processed. Function countCaughtFish(fish: int[], baits: int[]) → int Examples Example 1 fish = [1,2,3] baits = [1] return = 2 The bait of size 1 catches fish of sizes 3 and 2. It cannot catch the remaining fish of size 1, so the result is 2. Example 2 fish = [2,2,3,4] baits = [1] return = 3 The only bait is smaller than every fish, but it can be used only three times. It catches fish of sizes 4, 3, and 2. Example 3 fish = [1,4,3,2] baits = [1,1] return = 3 The first bait catches fish of sizes 4, 3, and 2. The only remaining fish has size 1, so the second bait cannot catch it. Constraints 1 ≤ fish.length ≤ 10^5 1 ≤ baits.length ≤ 10^5 1 ≤ fish[i] ≤ 10^9 1 ≤ baits[i] ≤ 10^9
Reported by candidates. Source: FastPrep
Pattern and pitfall
What it really reduces to: sort fish, sort baits descending, and walk with pointers. Process each bait from largest to smallest. The largest remaining fish that a bait can catch is the biggest fish strictly smaller than the bait's size... wait, no, the bait must be strictly smaller than the fish. So the bait catches fish larger than it, and the largest remaining fish is simply the max of what's left. Keep fish sorted descending with a pointer. For each bait, up to 3 times, check if the current largest fish is greater than the bait. If yes, count it and advance. If not, stop, since no remaining fish qualifies. The pitfall is using less-than-or-equal instead of strict, and brute-force removal from a list, which is O(n^2) at 10^5. Sorting gives O(n log n). If you freeze during the live OA, StealthCoder is the hedge that reads the prompt and hands you the pointer logic.
The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.
You can drill Catch Fish with Reusable Baits cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Hudson River Trading's OA.
Hudson River Trading reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Catch Fish with Reusable Baits FAQ
What's the trick in the Catch Fish with Reusable Baits problem?+
Sort fish descending and process baits largest to smallest. Since each bait takes the largest remaining fish, you only ever check the top of the fish list. If it's strictly bigger than the bait, catch it and move on. Otherwise that bait is done.
How hard is this Hudson River Trading OA question really?+
Easy to medium. There's no fancy structure needed, just sorting and a pointer. The difficulty is reading the rules carefully: strict comparison, three uses per bait, and the processing order. Most mistakes come from misreading, not from the algorithm.
Do I need a heap or sorted set for this?+
No. A descending sorted array with one moving index works, because caught fish are always the largest remaining. Removing from the front is just incrementing the pointer. A heap would work but adds log factors and complexity for nothing.
What edge cases should I test before submitting?+
Test a bait equal in size to a fish, which must not catch it. Test one bait with many fish, which caps at 3. Test more baits than fish. Test all fish smaller than every bait. Also check large values up to 10^9 don't overflow your types.
How do I prep for this in 48 hours?+
Write this one from scratch twice, with sorting and a pointer loop. Then do a few greedy matching problems with sorted arrays and two pointers. Focus on reading constraints and counting loops precisely, since the n of 10^5 rules out quadratic solutions.