Design a playlist library that stores songs and lets users organize them into playlists. Each song is created once in the library, then any number of playlists may refer to that same song object.
The provided PlaylistLibrary class supports these operations:
PlaylistLibrary() creates an empty library with no playlists.boolean addSong(String title) adds a song to the library and returns true. A title already in the library is refused with false.boolean createPlaylist(String name) creates an empty playlist and returns true. A name already used is refused with false.boolean addToPlaylist(String playlistName, String songTitle) puts that song into that playlist and returns true. It changes nothing and returns false when the playlist does not exist, when the song is not in the library, or when the playlist already contains it.boolean clearPlaylist(String name) empties that playlist and returns true, or returns false when it does not exist. The songs stay in the library.int songCount() returns how many songs the library holds.String[] playlistSongs(String name) returns that playlist's song titles in insertion order. An unknown playlist returns an empty result.A playlist aggregates songs but does not own them. Clearing one playlist removes only its references: the songs remain in the library and in any other playlists that contain them.
Your task is to implement the Song and Playlist classes expected by the provided library. Do not modify PlaylistLibrary. Song represents one library-owned song, while Playlist stores ordered references to existing Song objects and rejects duplicate references.
Input:
Output:
Explanation: Song A is created in the library before Gym refers to it. Adding that reference does not create another song, so the library count remains 1.
Input:
Output:
Explanation: Gym and Chill both refer to the same library-owned song. The song appears in both playlists, but the library still stores it only once.
1 <= title.length <= 40 and 1 <= name.length <= 40100 calls will be made across all methods.Full marks when songs are created by and owned by the library, and a playlist holds references to existing songs rather than copies of them. Lose points heavily when a playlist stores song titles as strings, or when adding to a playlist creates a new song.
Full marks when clearing a playlist empties only that playlist and leaves every song in the library, and when the same song can sit in several playlists at once. Lose points when clearing removes songs from the library, or when a song can belong to only one playlist.
Full marks when adding a song that is not in the library is refused, duplicates within one playlist are refused, and playlists report songs in insertion order. Lose points for duplicated lookup code or 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 PlaylistLibrary() | null |
| addSong("Song A") | true |
| createPlaylist("Gym") | true |
| addToPlaylist("Gym", "Song A") | true |
| playlistSongs("Gym") | ["Song A"] |
| songCount() | 1 |
A song is added to the library first, then referred to by a playlist. The library still holds one song.
Run checks these cases. Submit also runs a larger hidden set.

