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 in the subset satisfies either or . 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. Before reading the solution, try to identify the base case and recursive relationship yourself.