Reported September 2026
Millenniummath

Calculate the Half Spread

Reported by candidates from Millennium's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Millennium OA. Under 2s to a working solution.
Founder's read

The edge case that breaks a naive solution on the Millennium "Calculate the Half Spread" OA, reported in September 2026, is floating point. The formula looks like one line of arithmetic, but the statement says to read inputs as exact decimals and round halfway cases upward. Plain doubles will quietly fail hidden tests. This isn't really a BFS problem despite the hint. It's exact decimal math with a max and a rounding rule. If you blank on the exact-arithmetic part during the live assessment, StealthCoder runs invisibly as a safety net and gives you the approach.

The problem

A market-making model starts with a base half spread, then adjusts it for volatility and liquidity. Higher volatility must make the quote wider, while higher liquidity must make it narrower.
Implement calculateHalfSpread and compute:
modeledHalfSpread = baseHalfSpread * (1 + volatility) / liquidityScore
Each input is a decimal value with at most seven digits after the decimal point; interpret those decimal values exactly. Return the larger of modeledHalfSpread and minimumHalfSpread. Round the result to six decimal places; an exact halfway case rounds upward.

Function
calculateHalfSpread(baseHalfSpread: double, volatility: double, liquidityScore: double, minimumHalfSpread: double) → double

Examples
Example 1
baseHalfSpread = 0.02
volatility = 0.5
liquidityScore = 0.75
minimumHalfSpread = 0.03
return = 0.04
The modeled value is 0.02 * 1.5 / 0.75 = 0.04. It is larger than the minimum 0.03.
Example 2
baseHalfSpread = 0.01
volatility = 0.1
liquidityScore = 1.0
minimumHalfSpread = 0.02
return = 0.02
The modeled value is 0.011, so the minimum half spread 0.02 becomes the result.

Constraints
0 < baseHalfSpread <= 100
0 <= volatility <= 10
10^-6 <= liquidityScore <= 1
0 <= minimumHalfSpread <= 100
Every input has at most seven digits after the decimal point.
The unrounded modeled value is at most 10^9.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is to stop using doubles. Every input has at most seven decimal digits, so scale each to an integer by multiplying by 10^7 (parse the string, don't multiply a float). Then modeled = base * (10^7 + vol) / liq, all in big integers, with the scaling factors tracked carefully. Compare against the minimum using the same exact fractions, so no precision loss decides the max. For rounding to six places, use integer division with a half-up rule: add half the denominator before dividing. The pitfall is a result like 0.0000005 exactly, where double error rounds the wrong way. Another one is liquidityScore as small as 10^-6, which pushes results toward 10^9, so use 64-bit or big integers, never 32-bit. In Python use Fraction or Decimal. In Java use BigDecimal with HALF_UP. If you freeze on the scaling math during the live OA, StealthCoder is the hedge that reads the problem and hands you the exact-arithmetic solution.

StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.

If this hits your live OA

You can drill Calculate the Half Spread 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. If you're reading this with an OA window open, you're who this was built for.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Millennium's OA.

Millennium reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Calculate the Half Spread FAQ

What's the trick in the Millennium Calculate the Half Spread problem?+

Exact decimal arithmetic. The formula is trivial, but the statement demands exact interpretation of inputs and half-up rounding at six places. Use BigDecimal, Python Decimal or Fraction, or scale everything to integers. Doubles will pass the samples and fail hidden halfway cases.

Is this really a breadth-first search problem?+

No. The pattern tag is misleading. There's no graph or traversal here. It's a math and precision problem: compute one expression, take the max with the minimum, then round. Treat it as number handling, not algorithms.

How do I handle the rounding rule correctly?+

Compute the exact value as a fraction or high-precision decimal, then round to six places using half-up. In Java that's RoundingMode.HALF_UP. In Python, Decimal with ROUND_HALF_UP. Don't round a double with a built-in round, since it can use banker's rounding or inherit float error.

What edge cases should I test before submitting?+

Test liquidityScore at 0.000001 for huge outputs, volatility at 0 and 10, and a case where the modeled value equals the minimum exactly. Also test a result landing exactly on a halfway point at the seventh decimal, like x.xxxxxx5, to confirm it rounds up.

How do I prepare for this in 48 hours?+

Practice parsing decimal strings into exact types and rounding half-up in your language. Write this function once with BigDecimal or Decimal and run the two examples plus a halfway case. That covers nearly everything this problem tests.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Millennium.

OA at Millennium?
Invisible during screen share
Get it