## Interview Question

Country: United States

Comment hidden because of low score. Click to expand.
0
of 0 vote

This can be solved by inverting the Map which is genre map.
Once we invert the genre map, we know genre of each song, and now we can
traverse the song list of people while counting the genre of each song, and bingo!

This translates into :

``````people = {
"David": ["song1", "song2", "song3", "song4", "song8"],
"Emma": ["song5", "song6", "song7"] }

genres = {
"Rock": ["song1", "song3"],
"Dubstep": ["song7"],
"Techno": ["song2", "song4"],
"Pop": ["song5", "song6"],
"Jazz": ["song8", "song9"]
}
song_to_genre = fold( genres.entries , dict() ) as {
genre = \$.key
song_list = \$.value
for ( song : song_list ){
\$.p[song] = genre
}
\$.p // return
}
// now the trivial counting matter
for ( person : people.keys ){
persons_songs = people[person]
counter = dict()
for ( song : persons_songs ){
if ( song !@ counter ){
counter[song_to_genre[song]] = 0
}
counter[song_to_genre[song]] += 1
}
// find the genre with maximal count now?
#(min,Max) = minmax( counter.entries ) where { sign( \$.left.value - \$.right.value ) }
printf("Person : %s , Genre: %s %n", person, Max.key )
}``````

Comment hidden because of low score. Click to expand.
0
of 0 vote

``````Map<String, List<String>> personMusic = new HashMap<>(  );
Map<GENTYPE, List<String>> generic = new LinkedHashMap<>(  );

personMusic.put( "Chaitu", new ArrayList<>(  ) );
personMusic.put( "Abhi", new ArrayList<>(  ) );

generic.put( GENTYPE.Rock,new ArrayList<>(  ) );
generic.put( GENTYPE.Dubstep,new ArrayList<>(  ) );
generic.put( GENTYPE.Techno,new ArrayList<>(  ) );
generic.put( GENTYPE.Pop,new ArrayList<>(  ) );
generic.put( GENTYPE.Jazz,new ArrayList<>(  ) );

System.out.print( generic );

Map<String, String > favGen = new HashMap<>(  );

personMusic.entrySet().stream().forEach( person->{
List<String> personSongs = person.getValue();
int songsCounter=0;
for(Map.Entry <GENTYPE, List<String>> entry : generic.entrySet()){
List<String> tempList = new ArrayList<>( personSongs );
tempList.retainAll( entry.getValue());
if(tempList.size() > songsCounter){
songsCounter = tempList.size();
favGen.put(person.getKey(), entry.getKey().getCode());
}
}
} );

System.out.println( favGen );``````

Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

### Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

### Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.