Problem · Math

Cluster Size on Disk

Learn this problem
EasyUpstart logoUpstartFULLTIMEOA

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) → long

Examples

Example 1

clusterSize = 4096fileSize = 1return = 4096

Even one byte requires one complete 4096-byte cluster.

Example 2

clusterSize = 4096fileSize = 8193return = 12288

Two 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 problems

drafts saved locally
public long computeSizeOnDisk(long clusterSize, long fileSize) {
    // Write your code here.
}
clusterSize4096
fileSize1
expected4096
checking account