368. Largest Divisible Subset
Problem Statement
Given a set of distinct positive integers nums
, return the largest subset answer
such that every pair (answer[i], answer[j])
of elements in this subset satisfies:
answer[i] % answer[j] == 0
, oranswer[j] % answer[i] == 0
If there are multiple solutions, return any of them.
Example 1:
Example 2:
Constraints:
1 <= nums.length <= 1000
1 <= nums[i] <= 2 * 109
All the integers in
nums
are unique.
Intuition
Links
Video Links
Approach 1:
Approach 2:
Approach 3:
Approach 4:
Similar Problems
Last updated