r/algorithms • • 5h ago

Help I can redo familiar problems, but new matrix and graph problems stump me. How do I improve?

4 Upvotes

I keep getting stuck on matrix, tree, and graph problems, even after spending time practicing. Matrix problems are especially difficult for me.

I can solve basic tree problems and problems I've solved before, but I struggle when I face something new.

What would you recommend practicing first? Is there a good progression from basic tree problems to matrix and graph problems that could help me build understanding instead of relying on having seen the problem before?


r/algorithms • • 5h ago

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

3 Upvotes

How would you clarify the requirements for this audiobook recommendation prompt before starting to code? The setting is a roughly 30-minute interview slot after behaviorals, so I'm also wondering whether the expectation is low-level design (LLD) rather than just an algorithm.

Prompt: Audiobook Recommendation System

Given a log of "audiobook completed" events, write code to implement an audiobook recommendation system. It should answer "What should I listen to next?" based on the listening patterns in the log.

For example, if many customers listened to BookA followed by BookB, then given BookA as input, the recommendation system should return BookB.

python 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 """

What I'm most interested in is the requirements discussion. "BookA followed by BookB" could mean the very next completion for the same customer, or any later completion. Would you also ask whether repeated listens count multiple times, whether to rank by events or distinct customers, and how ties or books with no follow-up should work?

Which questions would you prioritize within that time limit, and what implementation scope would you agree on before coding?