Problem · Math
Cluster Size on Disk
Learn this problemProblem 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.