Catch Fish with Reusable Baits
Updated
Problem statement
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
3times.
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[]) → intExamples
Example 1
fish = [1,2,3]baits = [1]return = 2The 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 = 3The 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 = 3The 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^51 ≤ baits.length ≤ 10^51 ≤ fish[i] ≤ 10^91 ≤ baits[i] ≤ 10^9
More Susquehanna International Group (SIG) Online Assessment questions
- Bold Play to Reach a GoalOA · Seen Nov 2026
- Cats, Truth and Who Has MoreOA · Seen Nov 2026
- Counting Cows by Their LegsOA · Seen Nov 2026
- Enough Muffins for the LineOA · Seen Nov 2026
- Expected Consecutive Pairs Among Chosen NumbersOA · Seen Nov 2026
- Four-by-Four Boundary GridOA · Seen Nov 2026
- Frog Paths Without Long RunsOA · Seen Nov 2026
- Higher Roll, or Lose the SumOA · Seen Nov 2026
- Is a Popular Story Fake?OA · Seen Nov 2026
- Knights, Knaves and Their StatementsOA · Seen Nov 2026
Similar questions at other companies
- Can Every Package Fit in a BoxIMC Trading · OAIMC Trading interview questions
- Minimum Tunnel Crossing TimeArcesium · OAArcesium interview questions
- Get Maximum PairsAmazon · OA
- Find Maximum GreatnessTwilio · OATwilio interview questions
- Binge WatchingVanguard · OAVanguard interview questions
- Maximum Easy Tasks After RearrangingIBM · OAIBM interview questions
- Latest Arrival to Catch a BusAutodesk · OAAutodesk interview questions
- Minimum Removals to Balance ArraySalesforce · OASalesforce interview questions
- Minimum Machines for TasksExpedia · OAExpedia interview questions
- Find Minimum Possible SizeMathWorks · OAMathWorks interview questions