Read a File from Distributed Chunks
Updated
Problem statement
A file is split into chunkCount chunks. Each chunk has an ID, and the IDs the file needs are exactly 0 through chunkCount - 1. The chunks are kept in different storage places, and their responses come back in no particular order. The arrays chunkIds, chunkData, and readable describe these responses.
Rebuild the whole file: join the chunk data in increasing ID order and return it.
Return READ_ERROR instead if any of these is true:
- An ID the file needs is missing.
- An ID appears more than once, or is outside the needed range.
- The three response arrays do not all have the same length.
- A chunk the file needs is not readable.
A readable chunk may hold an empty string. That is fine: its data still counts as part of the 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 responses arrive out of order. Sorted by ID, chunk 0 is "Hello ", chunk 1 is "world", and chunk 2 is "!". Joining them gives "Hello world!".
Example 2
chunkCount = 3chunkIds = [0,1,1]chunkData = ["a","b","c"]readable = [true,true,true]return = "READ_ERROR"ID 1 appears twice and ID 2 is missing, so the answer is READ_ERROR.
Example 3
chunkCount = 2chunkIds = [1,0]chunkData = ["tail","head"]readable = [false,true]return = "READ_ERROR"The chunk with ID 1 cannot be read, so the file cannot be rebuilt and the answer is READ_ERROR.
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.
More Hudson River Trading interview questions
- Tiered Expiring Item StorePHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Aligned Free-List Memory AllocatorONSITE INTERVIEW · Seen Aug 2026
- Best Expected Result in Simplified BlackjackONSITE INTERVIEW · Seen Apr 2025
- Format a Signed Integer with CommasPHONE SCREEN · Seen Nov 2026
- Order and Batch Open-Close LifecyclePHONE SCREEN · Seen Nov 2026
- Count Palindrome Addition ChoicesOA · Seen Nov 2026
- Tilting Maze BallPHONE SCREEN · Seen Oct 2026
- Count Multiples of Three with Two SevensOA · Seen Oct 2026
- Recursively Expanded Shell Command CountsOA · Seen Oct 2026
- Rotate Matrix Regions Around the DiagonalsOA · Seen Oct 2026
Similar questions at other companies
- P&L Leaderboard OperationsBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
- Schedule Invoice Emails and DelinquenciesStripe · ONSITE INTERVIEWStripe interview questions
- Pins Violation Log QueriesPinterest · PHONE SCREENPinterest interview questions
- Resource Reconciler: Plan and Apply CreatesPerplexity AI · PHONE SCREENPerplexity AI interview questions
- HTTP Request RedirectionAmazon · OA
- Aggregate Paginated Project Run RecordsReplit · OA
- Credit Card Command ProcessorChime · PHONE SCREEN
- Macaron Order with Set DiscountsShopify · OAShopify interview questions
- Parcel Attribute Store with TTLAirbnb · OAAirbnb interview questions
- Popular and Instant-Runoff Election WinnersCoursera · PHONE SCREEN