InterviewLegend

Trees & Tries

Alex Chen26 min readUpdated

Trees and tries are the tree-shaped corner of Spotify's coding surface, and the two traversals behind them, DFS and BFS, recur across the whole loop. Spotify tends to frame them in product language: walk a playlist-folder hierarchy, follow user-to-content links, find a path in the artist graph. The trie shows up somewhere more specific, the search box that completes a track or podcast name as you type. Underneath both sits standard binary-tree and prefix-tree material, run live on CoderPad and tested against real inputs.

Treat this cluster honestly. There is no signature algorithm here. Trees are a smaller slice of the loop than the hashing and sliding-window clusters. What you get is the usual tree-and-trie spine pointed at Spotify's product surfaces: Max Depth shows up as folder depth, autocomplete as the search bar. The actual work is narrow. Drill the two templates that fold almost every problem in this space into a few lines. Then prove them on one tree problem and one trie problem you can run and narrate.

The Spotify angle
One recursion shape answers most binary-tree prompts here, so name what each node hands its parent before you reach for a global variable. The shape is a depth-first helper that returns a single fact about the subtree below it. A value held outside the recursion absorbs the answer that spans both sides. Maximum Depth, the recurring easy starter, returns the taller branch plus one. Diameter returns that same depth while an outer maximum watches the path that turns at a node. Validate-BST hands up an allowed value range. Lowest common ancestor reports whichever child found a target. Narration counts here, more than raw speed. So say the return value out loud, "this helper returns the subtree depth," before you write a line of the helper.

SpotifyPremium lesson · Coding round

The 2 Spotify problems are below.

  1. A Premium questionCoding · Medium
  2. A Premium questionCoding · Medium

Each with hints, the follow-up and a tested solution.

Get the Spotify questions

$49 a year · all 100 companies · cancel anytime

From 20,000+ candidate reports, forum threads behind logins and write-ups in Chinese.

Had your Spotify interview?Tell us what they asked. Reviewed before it goes in, never with your name.
Spotify interview guide

Know what Spotify asks before you walk in.

11 coding · 5 system design · 23 behavioral questions

Get Premium$49 a year · Cancel anytime
Or start freeNo card.

Get their questions first.

InterviewLegend is independent and not affiliated with or endorsed by any company it covers.