r/algorithms • • 3d ago

Help Audiobook recommendation from completion logs: what would you clarify before coding?

Suppose this comes up in a roughly 30-minute interview slot after behaviorals:

Given a log of "audiobook completed" events, implement a recommendation system that answers "What should I listen to next?" If many customers listened to BookA followed by BookB, an input of BookA should return BookB.

logs = """
    2025-08-09T03:25:11Z,Customer1,BookA
    2025-08-09T04:10:50Z,Customer2,BookB
    2025-08-09T12:01:24Z,Customer2,BookC
    2025-08-09T15:33:49Z,Customer3,BookB
    2025-08-10T07:54:35Z,Customer1,BookB
    2025-08-10T08:00:08Z,Customer4,BookD
    2025-08-10T11:29:31Z,Customer3,BookE
    2025-08-10T23:45:00Z,Customer5,BookF
    2025-08-10T23:51:20Z,Customer6,BookB
    2025-08-11T09:05:16Z,Customer1,BookC
    2025-08-11T20:12:57Z,Customer3,BookA
    2025-08-11T20:59:32Z,Customer7,BookB
    2025-08-11T21:00:13Z,Customer2,BookB
    2025-08-12T05:17:23Z,Customer1,BookB
    2025-08-12T18:19:07Z,Customer1,BookC
    2025-08-12T22:22:42Z,Customer5,BookE
    2025-08-13T00:07:58Z,Customer7,BookG
    2025-08-13T04:02:29Z,Customer6,BookE
    2025-08-14T21:12:33Z,Customer3,BookG
    2025-08-14T23:49:00Z,Customer1,BookF
    2025-08-15T12:00:01Z,Customer3,BookC
"""

Before coding, I'd want to clarify:

  • Does BookB have to be the next completion for that customer, or can it be any later listen?
  • Do repeat listens count again, or do we count distinct customers?
  • How should ties and books with no follow-up work?

The first answer seems especially important because it changes which pairs we count. Would you treat this as an algorithm/data-structure problem, or ask whether the interviewer expects low-level design too?

I'm interested in practicing the scoping step: choose a real technical interview question, agree on the smallest complete version, then implement it. For this one, which questions would you ask first, and what would you leave out to finish in time?

3 Upvotes

2 comments sorted by

1

u/AdvanceAdvance 8h ago

There are always three answers: "Do it this way"; "How can I cheat"; and "What's the business reason."

"Do it this way" can be solved either with clustering or just brain dead matching. Brain dead matching, meaning other users that match all but one or two books and recommend the other book, work well. It's a fun debate about just how bad the algorithm is with 1B records. This is the algorithm that recommends The Hobbit if you liked Lord of the Rings and haven't seen it.

"How can I cheat" would usually go into metadata, like books in a series or the expected order of listening. It can try to force users onto 'tracks' where the next n books are prerecommended.

"What's the business reason" pushes hard on tracks, recommends books that are cheap to stream, pushes physical tie-ins like posters and workbooks.

In all cases, there are infinite number of detail questions, like repeat listens, immediate response time, batch compute time, measurement of success, value of A/B testing, etc. Most of the details don't really matter.

0

u/No_Discount_1199 3d ago

I'd spend the first five minutes pinning down what "followed by" actually means — the very next thing they finished, or anything they finished later? — plus whether repeats and abandoned books count. Then ask what should happen when the input book never appears in the log, and how big the log can get. Those answers decide your data structures and edge cases, which is the whole point of the exercise.