Custom Playlist Picture System with Owner-Only Access Control

Quick Overview

Implement an in-memory class that manages custom pictures for music playlists, where only the owner may upload, update, delete or transfer ownership and any user may view. It tests access-control checks, a consistent order of error handling, and edge cases such as duplicate uploads and ownership transfer.

Custom Playlist Picture System with Owner-Only Access Control

Company: Spotify

Role: Software Engineer

Category: Software Engineering Fundamentals

Difficulty: easy

Interview Round: Other

Design a system that manages custom images for music playlists. Each playlist has a single owner who has exclusive permission to upload, update and delete the playlist's picture. Any user can view a playlist's picture. The system must enforce access control: mutating operations (upload, update, delete, transfer ownership) are restricted to the playlist owner, while read operations (view, get owner) are available to all users. Handle edge cases such as operating on non-existent playlists, duplicate uploads, deleting when no image exists, and ownership transfers that change who has edit permissions. Implement the following methods: - `create_playlist(user_id: int, playlist_id: int) -> str`: create a new playlist owned by the given user. Returns `"Playlist created"` on success, or `"Playlist already exists"` if the playlist ID is already taken. - `upload_picture(user_id: int, playlist_id: int, image_url: str) -> str`: upload a picture for a playlist. Only the owner can upload. Returns `"Image uploaded"` on success, `"Playlist not found"` if the playlist does not exist, `"Permission denied"` if the user is not the owner, or `"Image already exists"` if a picture is already set. - `update_picture(user_id: int, playlist_id: int, image_url: str) -> str`: replace the existing picture for a playlist. Only the owner can update. Returns `"Image updated"` on success, `"Playlist not found"`, `"Permission denied"`, or `"No image to update"` if the playlist has no picture yet. - `delete_picture(user_id: int, playlist_id: int) -> str`: delete the picture for a playlist. Only the owner can delete. Returns `"Image deleted"` on success, `"Playlist not found"`, `"Permission denied"`, or `"No image to delete"` if the playlist has no picture. - `view_picture(user_id: int, playlist_id: int) -> str`: view the picture URL for a playlist. Any user can view. Returns the image URL, `"No image available"`, or `"Playlist not found"`. - `get_owner(playlist_id: int) -> int`: return the owner's user ID, or `-1` if the playlist does not exist. - `transfer_ownership(user_id: int, playlist_id: int, new_owner_id: int) -> str`: transfer ownership of a playlist to another user. Only the current owner can transfer. Returns `"Ownership transferred"` on success, `"Playlist not found"`, or `"Permission denied"`. When more than one error applies to a call, return the first one in this order: `"Playlist not found"`, then `"Permission denied"`, then the error about the picture's state. ```hint Preconditions first For each mutating method, write down the conditions that must hold before it changes anything, and test them in the stated order. A playlist that does not exist has no owner to compare against. ``` ### Examples Example 1: ```text system = PlaylistPictureSystem() system.create_playlist(1, 100) # -> "Playlist created" system.upload_picture(2, 100, "a.png") # -> "Permission denied" (user 2 is not the owner) system.upload_picture(1, 100, "a.png") # -> "Image uploaded" system.view_picture(2, 100) # -> "a.png" (anyone can view) system.update_picture(1, 100, "b.png") # -> "Image updated" system.view_picture(3, 100) # -> "b.png" system.create_playlist(2, 100) # -> "Playlist already exists" ``` Example 2: ```text system = PlaylistPictureSystem() system.create_playlist(1, 200) # -> "Playlist created" system.delete_picture(1, 200) # -> "No image to delete" system.update_picture(1, 200, "c.png") # -> "No image to update" system.upload_picture(1, 200, "c.png") # -> "Image uploaded" system.upload_picture(1, 200, "d.png") # -> "Image already exists" system.transfer_ownership(1, 200, 5) # -> "Ownership transferred" system.get_owner(200) # -> 5 system.delete_picture(1, 200) # -> "Permission denied" (user 1 no longer owns it) system.transfer_ownership(1, 200, 1) # -> "Permission denied" system.delete_picture(5, 200) # -> "Image deleted" system.view_picture(1, 200) # -> "No image available" system.get_owner(999) # -> -1 system.view_picture(1, 999) # -> "Playlist not found" ``` ### Constraints & Assumptions - `1 <= user_id, playlist_id, new_owner_id <= 10^4` - Image URLs are non-empty strings. - At most 1000 operations will be performed. - Playlist IDs are unique across the system. ### Clarifying Questions to Ask - Should `transfer_ownership` check that the new owner is a known user, and should a transfer to the current owner succeed? - Does the previous owner keep any rights after a transfer, for example as a collaborator? - Can playlists themselves be deleted, and if so, what happens to their picture? - Will calls arrive from several threads at once, or is the class used from a single thread? ### What a Strong Answer Covers - The state kept per playlist and how each lookup stays constant time. - One consistent order of checks for every mutating method, with the matching return string for each failure. - The difference between upload (no picture yet) and update (a picture must exist), and delete on a playlist with no picture. - How an ownership transfer changes who passes the permission check while leaving the picture untouched. - Time and space complexity, and a set of test calls that covers the edge cases in the prompt. ### Follow-up Questions - How would you add collaborators who may change the picture but may not transfer ownership? - What breaks if two threads call `upload_picture` on the same playlist at the same time, and how would you prevent it? - How would you keep a history of past pictures so the owner can revert to an earlier one? - If the pictures lived in an object store behind a CDN instead of in memory, what would change in this class?

Overview: Implement an in-memory class that manages custom pictures for music playlists, where only the owner may upload, update, delete or transfer ownership and any user may view. It tests access-control checks, a consistent order of error handling, and edge cases such as duplicate uploads and ownership transfer.

Spotify logo
Spotify
Nov 25, 2026
easySoftware EngineerOtherSoftware Engineering Fundamentals
0
0

Design a system that manages custom images for music playlists. Each playlist has a single owner who has exclusive permission to upload, update and delete the playlist's picture. Any user can view a playlist's picture.

The system must enforce access control: mutating operations (upload, update, delete, transfer ownership) are restricted to the playlist owner, while read operations (view, get owner) are available to all users.

Handle edge cases such as operating on non-existent playlists, duplicate uploads, deleting when no image exists, and ownership transfers that change who has edit permissions.

Implement the following methods:

  • create_playlist(user_id: int, playlist_id: int) -> str : create a new playlist owned by the given user. Returns "Playlist created" on success, or "Playlist already exists" if the playlist ID is already taken.
  • upload_picture(user_id: int, playlist_id: int, image_url: str) -> str : upload a picture for a playlist. Only the owner can upload. Returns "Image uploaded" on success, "Playlist not found" if the playlist does not exist, "Permission denied" if the user is not the owner, or "Image already exists" if a picture is already set.
  • update_picture(user_id: int, playlist_id: int, image_url: str) -> str : replace the existing picture for a playlist. Only the owner can update. Returns "Image updated" on success, "Playlist not found" , "Permission denied" , or "No image to update" if the playlist has no picture yet.
  • delete_picture(user_id: int, playlist_id: int) -> str : delete the picture for a playlist. Only the owner can delete. Returns "Image deleted" on success, "Playlist not found" , "Permission denied" , or "No image to delete" if the playlist has no picture.
  • view_picture(user_id: int, playlist_id: int) -> str : view the picture URL for a playlist. Any user can view. Returns the image URL, "No image available" , or "Playlist not found" .
  • get_owner(playlist_id: int) -> int : return the owner's user ID, or -1 if the playlist does not exist.
  • transfer_ownership(user_id: int, playlist_id: int, new_owner_id: int) -> str : transfer ownership of a playlist to another user. Only the current owner can transfer. Returns "Ownership transferred" on success, "Playlist not found" , or "Permission denied" .

When more than one error applies to a call, return the first one in this order: "Playlist not found", then "Permission denied", then the error about the picture's state.

Examples

Example 1:

system = PlaylistPictureSystem()
system.create_playlist(1, 100)              # -> "Playlist created"
system.upload_picture(2, 100, "a.png")      # -> "Permission denied"   (user 2 is not the owner)
system.upload_picture(1, 100, "a.png")      # -> "Image uploaded"
system.view_picture(2, 100)                 # -> "a.png"               (anyone can view)
system.update_picture(1, 100, "b.png")      # -> "Image updated"
system.view_picture(3, 100)                 # -> "b.png"
system.create_playlist(2, 100)              # -> "Playlist already exists"

Example 2:

system = PlaylistPictureSystem()
system.create_playlist(1, 200)              # -> "Playlist created"
system.delete_picture(1, 200)               # -> "No image to delete"
system.update_picture(1, 200, "c.png")      # -> "No image to update"
system.upload_picture(1, 200, "c.png")      # -> "Image uploaded"
system.upload_picture(1, 200, "d.png")      # -> "Image already exists"
system.transfer_ownership(1, 200, 5)        # -> "Ownership transferred"
system.get_owner(200)                       # -> 5
system.delete_picture(1, 200)               # -> "Permission denied"   (user 1 no longer owns it)
system.transfer_ownership(1, 200, 1)        # -> "Permission denied"
system.delete_picture(5, 200)               # -> "Image deleted"
system.view_picture(1, 200)                 # -> "No image available"
system.get_owner(999)                       # -> -1
system.view_picture(1, 999)                 # -> "Playlist not found"

Constraints & Assumptions

  • 1 <= user_id, playlist_id, new_owner_id <= 10^4
  • Image URLs are non-empty strings.
  • At most 1000 operations will be performed.
  • Playlist IDs are unique across the system.

Clarifying Questions to Ask Guidance

  • Should transfer_ownership check that the new owner is a known user, and should a transfer to the current owner succeed?
  • Does the previous owner keep any rights after a transfer, for example as a collaborator?
  • Can playlists themselves be deleted, and if so, what happens to their picture?
  • Will calls arrive from several threads at once, or is the class used from a single thread?

What a Strong Answer Covers Guidance

  • The state kept per playlist and how each lookup stays constant time.
  • One consistent order of checks for every mutating method, with the matching return string for each failure.
  • The difference between upload (no picture yet) and update (a picture must exist), and delete on a playlist with no picture.
  • How an ownership transfer changes who passes the permission check while leaving the picture untouched.
  • Time and space complexity, and a set of test calls that covers the edge cases in the prompt.

Follow-up Questions Guidance

  • How would you add collaborators who may change the picture but may not transfer ownership?
  • What breaks if two threads call upload_picture on the same playlist at the same time, and how would you prevent it?
  • How would you keep a history of past pictures so the owner can revert to an earlier one?
  • If the pictures lived in an object store behind a CDN instead of in memory, what would change in this class?