Apple | Phone | Most tracks

Difficulty: MEDIUMCategory: InterviewExperienceFrequency: 1Asked On 2020-02-21Added By Anonymous
Source: Link

Imagine a list of track plays logged by Apple music users across the world.


Given a comma-separated ordered list of these events, of the form:

1 user_id, track_id, timestamp


Write a program to compute the most common three-play sequence, and the

number of times that sequence was played on Apple music.

three-play sequence: means which 3 tracks were played in order(one after another) The count of the sequence(not the track itself)


Example input:

1[ 2 "daniel,ShapeOfYou,1519753867", 3 "daniel,Perfect,1519753868", 4 "martin,ShapeOfYou,1519753869", 5 "daniel,Thunder,1519753870", 6 "martin,ShapeOfYou,1519753871", 7 "martin,Despacito,1519753872", 8 "martin,ShapeOfYou,1519753873", 9 "martin,Perfect,1519753874", 10 "daniel,Despacito,1519753875", 11 "martin,Thunder,1519753875" 12]


More clarification ( as an example Daniel):

"daniel,ShapeOfYou,1519753867",

"daniel,Perfect,1519753868",

"daniel,Thunder,1519753870",

"daniel,Perfect,1519753868",

"daniel,Thunder,1519753870",

"daniel,Despacito,1519753875",


Example output:

(ShapeOfYou, Perfect, Thunder), 2 ( like which 3 tracks combination appear the most(in order ofcourse).. like t2 can appear anytime in the future after t1 and t3 appears after t1 and t2.. so which 3 combination appears most )

I couldn't solve it! :((

Comments