Created
May 16, 2025 14:30
-
-
Save axayjha/f3ed5931762828f9ed47bb41b96cf7ba to your computer and use it in GitHub Desktop.
q10
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
class Solution { | |
/** | |
* @param clusterSize The cluster size of a disk (in bytes). | |
* @param fileSize The size of a file (in bytes). | |
* @return The "size on disk" of this file, on this disk (in bytes). | |
*/ | |
public static int computeSizeOnDisk(int clusterSize, int fileSize) { | |
// Calculate the number of clusters needed. | |
// Using integer division, (fileSize + clusterSize - 1) / clusterSize | |
// correctly calculates the ceiling of fileSize / clusterSize for non-negative fileSize. | |
int numberOfClusters = (fileSize + clusterSize - 1) / clusterSize; | |
// The size on disk is the number of clusters multiplied by the cluster size. | |
int sizeOnDisk = numberOfClusters * clusterSize; | |
return sizeOnDisk; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment