Allocate Workers for a Production Ratio
Reported by candidates from Barclays's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Barclays reportedly served this one up in August 2026, and the name sounds scarier than the problem is. With inputs up to 10^9, any loop that simulates workers or items dies on the spot. The whole thing collapses to a few lines of arithmetic. If you've got an OA invite for Barclays this week, expect a problem that tests whether you read the constraints before typing. Know the formula cold and you finish fast. If you blank mid-assessment, StealthCoder is the invisible safety net that reads the screen and hands you the solution.
The problem
A factory must produce two products in a fixed quantity ratio. You are given positive integers total, firstRatio, secondRatio, firstRate, and secondRate. The factory must produce exactly total items. The first and second product quantities must have ratio firstRatio : secondRatio. One first-product worker produces firstRate items per day. One second-product worker produces secondRate items per day. The ratio divides total exactly, and each product quantity is divisible by its corresponding per-worker rate. Return a two-element integer array containing the required first-product worker count followed by the required second-product worker count. Function allocateWorkers(total: int, firstRatio: int, secondRatio: int, firstRate: int, secondRate: int) → int[] Examples Example 1 total = 2160 firstRatio = 2 secondRatio = 1 firstRate = 18 secondRate = 24 return = [80,30] The ratio has three total parts, so the product quantities are 2160 * 2 / 3 = 1440 and 2160 * 1 / 3 = 720. The required worker counts are 1440 / 18 = 80 and 720 / 24 = 30. Example 2 total = 1000 firstRatio = 3 secondRatio = 2 firstRate = 20 secondRate = 25 return = [30,16] The product quantities are 600 and 400. Dividing by the corresponding daily rates gives 30 and 16 workers. Example 3 total = 630 firstRatio = 1 secondRatio = 2 firstRate = 7 secondRate = 14 return = [30,30] The two product quantities are 210 and 420. Although the quantities differ, the rates make both worker counts equal to 30. Constraints 1 <= total, firstRatio, secondRatio, firstRate, secondRate <= 10^9. firstRatio + secondRatio <= 2 * 10^9. total * firstRatio and total * secondRatio fit in a signed 64-bit integer. total * firstRatio and total * secondRatio are each divisible by firstRatio + secondRatio. Each resulting product quantity is divisible by its corresponding per-worker rate.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is pure math. Split total by the ratio: first quantity = total * firstRatio / (firstRatio + secondRatio), second = total * secondRatio / (firstRatio + secondRatio). Then divide each by its rate to get worker counts. Example 1 checks out: 1440 / 18 = 80 and 720 / 24 = 30. The constraints are the real pitfall. Values hit 10^9, and total * firstRatio can reach 10^18, so you need 64-bit integers. In Java use long, in C++ use long long. Python is safe by default. Multiply first, then divide, since the statement guarantees exact divisibility. Don't use floating point, it will lose precision at this size. Don't loop either, since brute force over 10^9 is dead. There's no sorting or search here, just careful casting. If the types trip you up under the clock, StealthCoder is there as the hedge on the live OA.
Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.
You can drill Allocate Workers for a Production Ratio 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. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Barclays's OA.
Barclays reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Allocate Workers for a Production Ratio FAQ
How hard is the Barclays Allocate Workers problem really?+
Easy on logic, easy to botch on types. The formula is two multiplications, two divisions, and two more divisions. The only real risk is 32-bit overflow, since total * ratio can reach 10^18. Use 64-bit integers and you're done in a few minutes.
What's the trick to solving it?+
Skip simulation entirely. Compute each product's quantity as total times its ratio part divided by the ratio sum, then divide by the worker rate. The statement guarantees every division is exact, so no rounding or remainder handling is needed.
Why does overflow matter here?+
Total and ratios go up to 10^9, so their product can reach about 10^18. That fits in signed 64-bit but overflows 32-bit ints. In Java or C++ cast to long before multiplying. Multiply first, then divide, so you stay exact.
Should I use floating point for the ratio?+
No. Doubles lose precision near 10^18 and can give an off-by-one worker count. Integer math works because the problem promises exact divisibility. Compute total * firstRatio, divide by the ratio sum, then divide by the rate, all with integers.
How do I prepare for this in 48 hours?+
Practice reading constraints first and picking the data type before writing code. Do a handful of ratio and proportion problems with large inputs. Test your solution against the three examples, especially Example 3 where both counts equal 30, then edge cases with values at 10^9.