Read Across Sound Tracks
Updated
Problem statement
Each sound track exposes a read(n) method that returns its next n characters of data (fewer if it has fewer left) and remembers where it stopped. For example, a track with data "abcde" returns "abc" for read(3) and then "de" for read(2).
Build a reader over a list of tracks, played back to back, whose read(n) returns the next n characters of the combined data. A read continues across track boundaries, so it may take characters from several tracks. If fewer than n characters are left, it returns all of them (possibly an empty string).
You are given the tracks' data as tracks and the sizes of consecutive read calls as reads. Return the string each call returns.
Function
readAcrossTracks(tracks: String[], reads: int[]) → String[]Examples
Example 1
tracks = ["a","bcd","ef"]reads = [2,1,3]return = ["ab","c","def"]- The first read takes
afrom track 0 and continues into track 1 forb:"ab". - The second read takes
c. - The third read takes
d, theneffrom track 2:"def".
Example 2
tracks = ["abc"]reads = [2,5,1]return = ["ab","c",""]"ab", then onlycis left, so the second read returns"c", and the third returns an empty string.
Example 3
tracks = ["","xy",""]reads = [1,1]return = ["x","y"]- Empty tracks contribute nothing: the reads return
"x"and"y".
Constraints
1 <= tracks.length <= 1000 <= tracks[i].length <= 100, and each track is lowercase English letters.1 <= reads.length <= 10001 <= reads[j] <= 500
More Airbnb interview questions
- Text JustificationPHONE SCREEN · Seen Nov 2026
- Decode and Store StringsPHONE SCREEN · Seen Oct 2026
- Print Sentences as TablePHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Detonate Bombs with Chain ReactionsPHONE SCREEN · Seen Aug 2026
- Smallest Common RegionPHONE SCREEN · Seen Aug 2026
- Longest Chain BookingPHONE SCREEN · Seen Aug 2026
- Nested List Iterator with RemovePHONE SCREEN · Seen Jul 2026
- Parse Query StringPHONE SCREEN · Seen May 2026
- Credit Accounts with Scheduled TransfersOA · Seen Oct 2026
- Parcel Attribute Store with TTLOA · Seen Oct 2026
Similar questions at other companies
- Stateful Log Transform and SearchRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
- In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
- File Storage ServiceCresta · PHONE SCREENCresta interview questions
- Return Every Matching DecryptionDuolingo · PHONE SCREENDuolingo interview questions
- Multiline Text Editor with Cursor MovementDatologyAI · PHONE SCREEN
- Reference-Counted Deduplicating File SystemCitadel · PHONE SCREENCitadel interview questions
- Machine Message RouterOpenAI · PHONE SCREENOpenAI interview questions
- In-Memory Filesystem NavigationUber · PHONE SCREENUber interview questions
- Text Document HistoryNotion · PHONE SCREEN · ONSITE INTERVIEWNotion interview questions
- String Copy and Move LifecycleSquarepoint Capital · PHONE SCREENSquarepoint Capital interview questions