Trains the technique from
LeetCode 318Maximum Product of Word LengthsThis 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 label printer is loaded with a set of ribbons. Ribbon i carries the code codes[i], written in lowercase English letters.
The printer has one ink channel per letter of the alphabet, so two ribbons can run together only when no letter appears on both of them. The span of such a pairing is the product of the lengths of the two codes.
Return the largest span over all pairings the printer can run. If no two ribbons can run together, return 0.
Example 1
The ribbons carrying `sable` and `orchid` share no letter, so they can run together, and their lengths multiply to `5 * 6 = 30`.
Example 2
`ember` and `brace` both use `b`, `ember` and `camber` both use `m`, and `brace` and `camber` both use `c`. No pairing can run, so the answer is 0.
Example 3
The only pairing uses `ox` and `zip`, which share no letter, so the span is `2 * 3 = 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_ribbon_pairing(codes: list[str]) -> int:public int bestRibbonPairing(String[] codes)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.