Minimum Cost to Merge Adjacent OneDrive Log Chunks

Last updated: November 29, 2026

Quick Overview

A OneDrive sync client stores a log as an ordered list of chunk sizes. Merging two adjacent chunks costs the sum of their sizes; return the minimum total cost to merge everything into one chunk while preserving order.

Microsoft
Coding & Algorithms
Software Engineer
Microsoft
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

0

0 solved


A OneDrive sync client stores a log as an ordered list of chunk sizes. Merging two adjacent chunks costs the sum of their sizes; return the minimum total cost to merge everything into one chunk while preserving order.

An interval DP question that Microsoft onsite interviewers like because the adjacency constraint breaks the familiar Huffman greedy. Strong candidates explain why, define the interval state, and use prefix sums for the merge cost.

What the Interviewer Expects
  • Explain why a min-heap Huffman approach is wrong when only adjacent chunks may merge
  • Define dp[i][j] as the minimum cost to merge chunks i..j into one
  • Iterate by interval length so subproblems are ready
  • Use prefix sums so each merge cost is O(1)
  • State O(n^3) and mention the Knuth optimization
Key Topics to Cover
interval DP
prefix sums
optimal merge
Knuth optimization
OneDrive scenario
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
  • What if each merge combines exactly K adjacent chunks?
  • Reconstruct the merge order as a binary tree.
  • How does Knuth's optimization bring this to O(n^2), and why does it apply here?
  • What if order does not matter?
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 of positive chunk sizes in order.
  • Only adjacent chunks can merge; the result takes their place.
  • Output: minimum total cost; 0 for zero or one chunk....
High-Level Design

Huffman merges the two smallest anywhere, which may not be adjacent. Instead think about the last merge: chunks i..j become one by merging a left part i..k and right part k+1..j, each already merged. ...


Submit Your Answer
Markdown supported