Skip to content

Instantly share code, notes, and snippets.

@axayjha
Created May 16, 2025 14:30
Show Gist options
  • Save axayjha/f3ed5931762828f9ed47bb41b96cf7ba to your computer and use it in GitHub Desktop.
Save axayjha/f3ed5931762828f9ed47bb41b96cf7ba to your computer and use it in GitHub Desktop.
q10
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