Problem · Array
Read a File from Distributed Chunks
Learn this problemProblem statement
A logical file consists of chunkCount chunks with required identifiers from 0 through chunkCount - 1. The arrays chunkIds, chunkData, and readable describe unordered responses from distributed storage locations.
Return the logical file by concatenating the chunk data in increasing identifier order.
Return READ_ERROR instead when any of these conditions holds:
- a required identifier is missing;
- an identifier is duplicated or outside the required range;
- the response arrays have different lengths; or
- any required chunk is not readable.
A readable chunk may contain an empty string. Its data is still part of the logical file.
Function
readLogicalFile(chunkCount: int, chunkIds: int[], chunkData: String[], readable: boolean[]) → StringExamples
Example 1
chunkCount = 3chunkIds = [2,0,1]chunkData = ["!","Hello ","world"]readable = [true,true,true]return = "Hello world!"The storage responses are unordered, but identifiers 0, 1, and 2 reconstruct the file in that order.
Example 2
chunkCount = 3chunkIds = [0,1,1]chunkData = ["a","b","c"]readable = [true,true,true]return = "READ_ERROR"Identifier 1 is duplicated and identifier 2 is missing.
Example 3
chunkCount = 2chunkIds = [1,0]chunkData = ["tail","head"]readable = [false,true]return = "READ_ERROR"The chunk with identifier 1 cannot be read, so the logical file is not returned.
Constraints
1 <= chunkCount <= 10^50 <= chunkIds.length, chunkData.length, readable.length <= 10^5- The total length of all strings in
chunkDatais at most2 * 10^5. - Chunk data contains printable ASCII characters.