AlgoMaster Logo
AlgoMasterAnalyze Erasure-Coded Stripe Healthmedium

Analyze Erasure-Coded Stripe Health

medium

An erasure code with k data shards and m parity shards can reconstruct the stripe from any k distinct shards.

Design ErasureStripeAnalyzer(dataShards, parityShards):

  • status is HEALTHY with all k+m shards, DEGRADED with at least k, otherwise LOST.
  • failureMargin returns how many additional available shards may fail without losing readability: max(0, distinctAvailable - k).
  • repairReads returns 0 when healthy, k when degraded, and -1 when lost.
  • storageOverhead returns (k+m)/k, rounded to 5 decimals.

Shard IDs are in 0..k+m-1; duplicates may appear and count once.

Example 1:
Example 2:

Constraints

  • 1 <= dataShards <= 100, 1 <= parityShards <= 100
  • 0 <= availableShards.length <= 10^4
  • Every shard ID is valid.
Hints

Loading...
CallReturns
new ErasureStripeAnalyzer(4, 2)null
status([0,1,2,3,4,5])"HEALTHY"
failureMargin([0,1,2,3,4,5])2
repairReads([0,1,2,3,4,5])0
storageOverhead()1.5

All six shards are available, so two more may fail while four data-equivalent shards remain.

Run checks these cases. Submit also runs a larger hidden set.