Playlist


Java 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, efficiently with respect to time used, 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.setNextSong(second);
second.setNextSong(first);
    
System.out.println(first.isRepeatingPlaylist());
Java SE 8
   

  •   Example case: java.lang.UnsupportedOperationException at Playlist$Song.isRepeatingPlaylist(Playlist.java:15)
  •   Song will repeat: java.lang.UnsupportedOperationException at Playlist$Song.isRepeatingPlaylist(Playlist.java:15)
  •   Song will not repeat: java.lang.UnsupportedOperationException at Playlist$Song.isRepeatingPlaylist(Playlist.java:15)
  •   Performance test on a large playlist: java.lang.UnsupportedOperationException at Playlist$Song.isRepeatingPlaylist(Playlist.java:15)