Skip to the code
cf.
+25 XP

#527 Longest Divisible Chain of Breakpoints

medium

A design team wants a set of layout breakpoints where every larger breakpoint is a whole multiple of every smaller one, so grids line up at every size. widths holds distinct candidate widths.

Write longestDivisibleChain(widths) that returns the size of the largest subset in which, for every pair of values, the larger one is divisible by the smaller one.

Example 1

Input: widths = [3,5,10,20]
Output: 3

5, 10, and 20: each divides the next.

Example 2

Input: widths = [2,7]
Output: 1

Neither divides the other.

Constraints

  • 1 <= widths.length <= 1000
  • 1 <= widths[i] <= 2 * 10^9, all different
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).