Match Songs with Repeatable Animations
Problem statement
You are given arrays songs and animations. Every string has the form name:length, where length is a positive integer duration.
An animation is compatible with a song when its duration does not exceed the song duration and divides the song duration exactly. In that case, repeating the animation songDuration / animationDuration times fills the song.
For each song, scan animations from left to right and choose the first compatible animation. Return one string per song in the form animationName:repeatCount.
Function
matchSongsWithAnimations(songs: String[], animations: String[]) → String[]Examples
Example 1
songs = ["notion:180","voyage:185","sample:180"]animations = ["circles:360","squares:180","lines:37"]return = ["squares:1","lines:5","squares:1"]circles:360 is longer than every song. squares:180 is the first compatible animation for both 180-second songs and repeats once. For voyage:185, lines:37 is the first compatible animation and repeats 5 times.
Example 2
songs = ["loop:120"]animations = ["pulse:30","wave:40"]return = ["pulse:4"]Both animations divide 120, so input order chooses pulse:30. It repeats 4 times.
Constraints
1 <= songs.length <= 1001 <= animations.length <= 100- Every entry contains exactly one colon, a nonempty name without a colon, and a duration from
1through10^5. - Every song has at least one compatible animation.
Source note: Source screenshot from a reported Capital One online assessment; the captured slide shows the worked example.