Playlist


C# Algorithmic thinking Searching Public New

Easy 

15min


A playlist is considered a repeating playlist if any of the songs contain a reference to a previous song in the playlist. Otherwise, the playlist will end with the last song which points to null.

Implement a function IsRepeatingPlaylist that returns true if a playlist is repeating or false if it is not.

For example, the following code prints "True" as both songs point to each other.

Song first = new Song("Hello");
Song second = new Song("Eye of the tiger");
    
first.NextSong = second;
second.NextSong = first;

Console.WriteLine(first.IsRepeatingPlaylist());
C# 7.0, .NET Framework 4.7
   

  •   Example case: System.InvalidOperationException at Song.IsRepeatingPlaylist() in Playlist.cs:line 15
  •   Song will repeat: System.InvalidOperationException at Song.IsRepeatingPlaylist() in Playlist.cs:line 15
  •   Song will not repeat: System.InvalidOperationException at Song.IsRepeatingPlaylist() in Playlist.cs:line 15
  •   Performance test on a large playlist: System.InvalidOperationException at Song.IsRepeatingPlaylist() in Playlist.cs:line 15