Largest Set of Replica Sizes Where Each Divides the Next

Last updated: November 29, 2026

Quick Overview

A storage tier offers distinct block sizes, and a tiered cache needs a chain of sizes where every pair divides one another so blocks split evenly. Return the largest such subset of the given sizes.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Medium

0

0

0 solved


A storage tier offers distinct block sizes, and a tiered cache needs a chain of sizes where every pair divides one another so blocks split evenly. Return the largest such subset of the given sizes.

This tests an LIS-style DP with a non-obvious ordering trick, a pattern Google interviewers like for onsite rounds. They check that you sort first, explain transitivity of divisibility, and reconstruct the actual set.

What the Interviewer Expects
  • Sort sizes so that only earlier elements can divide later ones
  • Explain why pairwise divisibility reduces to a chain via transitivity
  • Define chain[i] as the longest chain ending at sizes[i]
  • Store parent pointers to rebuild the set
  • State O(n^2) complexity and when it is fine
Key Topics to Cover
1D dynamic programming
LIS variant
Sorting for DP order
Reconstruction
Divisibility
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • Count the number of largest chains.
  • Sizes go up to 10^6 but there are 10^5 of them. Can you do better than O(n^2)?
  • Allow the chain to skip at most one size that breaks divisibility.
  • Maximize the total size of the chain instead of its length.
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Input: list sizes of distinct positive integers. Output a largest subset in which for every pair (a, b), a divides b or b divides a. Any valid largest subset is accepted. In sorted order, the subset...

High-Level Design

Sort ascending. Let chain[i] be the size of the largest valid subset whose maximum element is sizes[i]. For each j < i with sizes[i] % sizes[j] == 0, the chain ending at j can be extended by i: ...


Submit Your Answer
Markdown supported