As reported: IMC Trading Java Software Engineer (Strategy) online assessment on HackerRank (2026), part 2 of 3: debugging — a program that reads stock market data from the command line, with the expected input and output given; debug it until all 10 test cases pass.
You are given a short program that reads stock trades and prints a summary per symbol. It compiles and runs, but its output is wrong. Fix the bugs — without rewriting it from scratch — until all 10 tests pass.
What the program should do. Each input line is one trade: SYMBOL PRICE QUANTITY, separated by spaces, with PRICE written with exactly two decimals (for example AAPL 150.25 100). For every symbol, in alphabetical order, output one line:
SYMBOL trades=<number of trades> volume=<total quantity> high=<highest price> low=<lowest price> vwap=<VWAP>
where VWAP (volume-weighted average price) is Σ(price × quantity) / Σ quantity, rounded half up to a cent. All prices are printed with two decimals.
The given code keeps a Stats record per symbol (trade count, volume, high, low, sum of prices and notional, all prices in integer cents), with helpers to parse a price into cents and to format cents back to 123.45. The main function loops over the input lines, updates the symbol's stats, and then formats one line per symbol in sorted order. Open Practice to read it in the editor, in any of the five languages.
Example 1
lines = ["AAPL 150.25 100", "MSFT 410.00 50", "AAPL 151.00 200"]
Output: ["AAPL trades=2 volume=300 high=151.00 low=150.25 vwap=150.75",
"MSFT trades=1 volume=50 high=410.00 low=410.00 vwap=410.00"]
Example 2
lines = ["IBM 99.99 10"]
Output: ["IBM trades=1 volume=10 high=99.99 low=99.99 vwap=99.99"]
Constraints: up to 10^4 lines; 0.01 ≤ PRICE ≤ 9999.99; 1 ≤ QUANTITY ≤ 10^4; symbols are 1–5 letters or digits.
Code runner format: one JSON value per line: lines. The program's summarize(lines) returns the output lines (in Java, TradeSummary.summarize).
Open Debug lab to work on a practice repo with a bug report like this one in a timed online workspace — as an online assessment or a live AI coding interview — then walk an AI interviewer through your fix.