Trains the technique from
LeetCode 368Largest Divisible SubsetThis 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.
An audio restoration lab logs the length of every reel it holds as a whole number of samples. The log, samples, holds one count per reel and no two counts are equal.
Two reels are rate-compatible when one reel's count is a whole multiple of the other's, in whichever direction that happens to hold.
A bundle is a set of reels in which every pair of reels is rate-compatible. A bundle holding a single reel therefore always qualifies.
Return the counts of a bundle holding as many reels as possible, listed in increasing order. Where several bundles are equally large, return the one whose increasing listing comes first lexicographically: read the two listings position by position and prefer the listing with the smaller count at the first position where they differ.
Example 1
Two divides four, two divides eight and four divides eight, so those three reels are pairwise rate-compatible and the listing is in increasing order.
Example 2
Within four, eight and sixteen every pair has one count as a whole multiple of the other.
Example 3
Both [1, 2, 4] and [1, 2, 6] hold three pairwise compatible reels, and the tie-break prefers the first, since four is below six at the earliest position where the two listings differ.
Example 4
Neither count is a whole multiple of the other, so these two reels are not rate-compatible and each stands alone as a bundle; the tie-break prefers the listing with the smaller count.
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 largest_divisible_subset(samples: list[int]) -> list[int]:public List<Integer> largestDivisibleSubset(int[] samples)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.