Trains the technique from
LeetCode 152Maximum Product SubarrayThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A board game deals out a row of scoring tiles. Tile i carries the whole number factors[i], which may be negative, zero or positive.
On your turn you pick one unbroken stretch of neighbouring tiles, hold at least one tile, and walk across the whole stretch. You enter with a score of 1 and your score is multiplied by each tile's number as you step onto it. Skipping a tile inside the stretch is not allowed.
Report the highest score any single stretch can leave you with.
Example 1
Walking all four tiles pairs the two negative numbers off against each other, giving 3 * -1 * -4 * 2 = 24. Stopping earlier never gets past 12.
Example 2
Both single negative tiles leave a negative score, so the best available stretch is one that steps on the zero tile.
Example 3
A stretch has to hold at least one tile, so the only choice available scores -6.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def best_tile_run(factors: list[int]) -> int:public int bestTileRun(int[] factors)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.