Get Smallest Base Segment
Problem statement
In Amazon's distributed storage network, some critical data segments are missing. They are represented by a string missingData. The system restores data by choosing a base segment of length segmentSize and repeatedly appending copies of that base segment to a generated string.
A base segment is valid if, after some number of replications, the generated string contains every character in missingData at least as many times as it appears in missingData.
Examples
Example 1
segmentSize = 2missingData = "aavvavv"return = "av"The character a appears 3 times and v appears 4 times. Both "av" and "va" require 4 replications. Since "av" is lexicographically smaller, it is returned.
Unlock this recently reported problem
FastPrep Pro gives you full access to interview problems reported within the last week.
- Full problem statement and constraints
- 1 more worked example, explained
- Guided hints and editorial
- Run your code on real test cases
$99 billed yearly — or $19 month-to-month. Cancel anytime.