Cluster Size on Disk
Updated
Problem statement
A storage device allocates file space in fixed-size clusters. A non-empty file occupies the smallest whole number of clusters whose combined capacity is at least the file's logical size.
Given a positive clusterSize in bytes and a non-negative fileSize in bytes, return the number of bytes allocated on disk. A file of size 0 occupies 0 bytes.
Function
computeSizeOnDisk(clusterSize: long, fileSize: long) → longExamples
Example 1
clusterSize = 4096fileSize = 1return = 4096Even one byte requires one complete 4096-byte cluster.
Example 2
clusterSize = 4096fileSize = 8193return = 12288Two clusters hold only 8192 bytes, so the file needs three clusters.
Constraints
1 <= clusterSize <= 10^9.0 <= fileSize <= 10^18.- The allocated result fits in a signed 64-bit integer.
More Upstart Online Assessment questions
- Buffet Day GainsOA · Seen Sep 2026
- Case-Insensitive Anagram CheckOA · Seen Sep 2026
- Filter Duplicates While Preserving OrderOA · Seen Sep 2026
- Scale Ingredient QuantitiesOA · Seen Sep 2026
- ABO Parent Genotype CombinationsOA · Seen Aug 2026
- Chunked Byte Stream ChecksumsOA · Seen Aug 2026
- Double Substitution DecryptionOA · Seen Aug 2026
- Add Drama to Text GroupsOA · Seen Jul 2026
- Lexicographic Word FrequenciesOA · Seen Jul 2026
- Minimum Absolute Pair DifferenceOA · Seen Jul 2026
Similar questions at other companies
- Summarize Taxi Drivers and RidesBoston Consulting Group · OABoston Consulting Group interview questions
- Total Cost Against the Lowest Earlier PricePayPal · OAPayPal interview questions
- Count Valid Square PairsAuxoAI · OA
- Counting Cows by Their LegsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
- Server InvestmentRippling · OARippling interview questions
- Basic Item DiscountsPalantir · OAPalantir interview questions
- Identification Number Check DigitAbridge · OAAbridge interview questions
- Count Substrings With Identical CharactersVirtu Financial · OAVirtu Financial interview questions
- Next Pascal Row CoefficientIntuit · OAIntuit interview questions
- Digit-Sum Sequence Join PointOpenAI · OAOpenAI interview questions