Data Structures & AlgorithmsVery hardCodeforces Div2 C · LeetCode-style

From [1, 2, 3, 4, 6, 8, 12, 16, 18, 24, 36], choose the largest subset in which every pair of elements (the smaller divides the larger). What is the size of such a subset?

  1. A. 11
  2. B. 5
  3. C. 4
  4. D. 7

Correct answer: B. 5

Sort, then build a DP where each number extends a chain ending at any smaller divisor; divisibility is transitive along a chain, so checking the divisor against the previous element is enough. The plain LIS treats 'larger' as the only requirement and gives a different answer.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic