Dynamic Programming21 sections · 916 units
Open in Course

LeetCode 368 Largest Divisible Subset - Problem Statement

LIS with divisibility

This is Largest Divisible Subset from LeetCode. Given a set of distinct positive integers, find the largest subset (a collection of elements, order doesn't matter) such that every pair (a,b)(a, b) in the subset satisfies either a÷ba \div b or b÷ab \div a. For [1, 2, 3], the answer is [1, 2] (or [1, 3]). For [1, 2, 4, 8], the answer is [1, 2, 4, 8].

Notice how this looks like LIS, but with divisibility instead of less-than.