YOE : 17 in java, includes 10 in android.
applied for senior engineer roles, hoping I'd be considered for Staff level roles also.
/**
interface Playlist {
@Nullable Song getNextSong();
boolean hasNextSong();
}
class Song {
String name;
public Song(String name) {
this.name = name;
}
}
class CollaborativePlaylist implements Playlist {
public CollaborativePlaylist(@NotNull List<Playlist> playlists) {
}
@Override
@Nullable
public Song getNextSong() {
}
@Override
public boolean hasNextSong() {
}
My brute-force solution, assuming Playlist.hasNextSong() works correctly to help achieve round-robin shuffle-feature.
class CollaborativePlaylist implements Playlist {
// Space - O ( N )
private Deque<Song> songsList;
public CollaborativePlaylist(@NotNull List<Playlist> playlists) {
songsList = new LinkedList<>();
prepareSongsList ( playlists );
}
private void prepareSongsList( List<Playlist> playlists ) {
int index = 0;
while ( index < playlists.size() ) {
if ( playlists.get( index ).hasNextSong() ) {
index = addSong ( playlists, index );
if ( index == playlists.size() ) {
index = 0;
}
} else {
index++;
}
}
}
private int addSong ( List<Playlist> playlists, int index ) {
if ( playlists.get( index ).hasNextSong() ) {
songsList.addFirst ( playlists.get(index).getNextSong() );
}
return ++index;
}
@Override
@Nullable
public Song getNextSong() {
return songsList.removeLast();
}
@Override
public boolean hasNextSong() {
return songsList.isEmpty();
}
}Outcome: Rejected, clearly I did not provide the most efficient and optimal solution, because I succumbed to anxiety.