Amazon VO 面试真题解析:Amazon Music Playlist Manager | 队列 / 数据结构

15次阅读
没有评论

Let’s create a music playlist manager for Amazon Music, which allows users to:

  • add songs to the playlist
  • play a song from the playlist in order

Implement the methods for adding and playing songs.

If the user wants to add another song while the playlist is full, the oldest-added song needs to be removed first.

这道题考察的是一个简单但非常典型的播放列表管理器:用户可以按顺序添加歌曲,并按加入顺序播放歌曲;当播放列表达到容量上限时,再加入新歌需要先移除最早加入的那首。题目核心是用队列思想维护歌曲的先后顺序,或者直接使用支持先进先出操作的数据结构来实现 <code>add</code> 和 <code>play</code>,从而保证“最旧的先被删、最早加入的先被播放”。

正文完
 0