Design a music catalog that stores artists and songs, then lets albums collect references to those existing songs. Every song belongs to one artist, and the same song may appear in several albums.
The provided MusicCatalog class supports these operations:
MusicCatalog() creates an empty catalog.int addArtist(String name) adds an artist and returns their id.int addSong(String title, int artistId) adds a song by that artist and returns its id, or -1 if the artist id is out of range.int createAlbum(String name) creates an empty album and returns its id.boolean addToAlbum(int albumId, int songId) adds the song to that album and returns true. It returns false if either id is out of range, if the album was removed, or if the song is already in that album.boolean removeFromAlbum(int albumId, int songId) takes the song out of that album and returns true, or returns false if the song was not in it or the album is unknown or removed.boolean removeAlbum(int albumId) removes the album and returns true, or returns false if it is unknown or already removed.String[] albumSongs(int albumId) returns the titles in that album, in the order they were added. A removed or unknown album returns an empty result.String artistOf(int songId) returns the name of the artist who recorded that song, or "UNKNOWN".int songCount() returns how many songs the catalog holds.int artistCount() returns how many artists the catalog holds.Artist, song, and album ids are assigned independently in insertion order, starting at 0. Songs and artists are never removed. Removing an album does not reuse its id or change any other id.
Your task is to implement the Artist, Song, and Album classes expected by the provided catalog. Do not modify MusicCatalog. A Song should refer to an existing Artist, while an Album should store ordered references to existing Song objects and reject duplicate references.
Input:
Output:
Explanation: Adele is added before Hello refers to her, and the song is created before album 25 collects it. The album lists the existing song, whose artist remains Adele.
Input:
Output:
Explanation: Both albums refer to the same Titan song. Removing A1 drops only that album; the catalog still owns the song, and A2 still lists it.
0 <= name.length, title.length <= 4020 artists, 20 songs, and 20 albums.100 calls in total are made across all methods.Full marks when removing an album leaves every song it held in the catalog and still answerable through `songCount` and `artistOf`. Lose points heavily when removing an album deletes its songs, which treats a collection as a container.
Full marks when the same song can be added to several albums and removing it from one album leaves it in the others, because each album holds a reference to the one song object. Lose points heavily when adding to an album copies the song, so the catalog holds several versions of the same track.
Full marks when a song is created against an existing artist and refuses an unknown one with `-1`, adding a song twice to the same album is refused, a removed or unknown album lists nothing and accepts nothing, and an unknown song reports `UNKNOWN` for its artist. Lose points for printing to stdout.
Passing every test is not enough on its own. A submission is accepted only when the design also clears the bar.
| Call | Returns |
|---|---|
| new MusicCatalog() | null |
| addArtist("Adele") | 0 |
| addSong("Hello", 0) | 0 |
| createAlbum("25") | 0 |
| addToAlbum(0, 0) | true |
| albumSongs(0) | ["Hello"] |
| artistOf(0) | "Adele" |
| songCount() | 1 |
An artist, a song by that artist, and an album collecting it. The album lists the song, and the song still names its artist.
Run checks these cases. Submit also runs a larger hidden set.

