Trains the technique from
LeetCode 3953Maximum Score with Co-Prime ElementThis 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.
Register values are given as nums, along with a ceiling maxVal.
Pick a whole number x from 1 to maxVal inclusive. Its score is x itself plus the total of every entry of nums sharing no common factor above one with x.
Return the largest score any pick can have.
Example 1
A pick shares a factor with some entries and not others, and the best pick trades its own size against what it rules out.
Example 2
The ceiling leaves only a pick of one, which shares no factor above one with anything, so the score is one plus the whole register.
Example 3
Every entry is 7, so a pick of 7 rules them all out and scores 7, while a pick of 6 keeps them all and scores 34.
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 max_score(nums: list[int], maxVal: int) -> int:public long maxScore(int[] nums, int maxVal)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.