GuitarConcert
SRM 366 · 2007-09-18 · by jthread
Problem Statement
You are a guitar player and you want to play a concert. Unfortunately, you don't have any good guitars left, so you need to buy some new guitars. You are given a
You have a list of songs that you would like to play at the concert. Certain songs cannot be played with certain guitars because they will sound weird, so you might not be able to play the entire concert with just one guitar. You are given a
You want your concert to be as long as possible, so your main goal is to play as many of the songs as possible (you can only play each song at most once). You also want to save your money, so you want to buy the least number of guitars required to play that maximum number of songs. Return a
Constraints
- guitarNames will contain between 1 and 10 elements, inclusive.
- guitarSongs will contain the same number of elements as guitarNames.
- Each element of guitarSongs will contain between 1 and 50 characters, inclusive.
- Each element of guitarSongs will contain the same number of characters.
- Each element of guitarSongs will contain only the uppercase letters 'Y' or 'N'.
- Each element of guitarNames will contain between 2 and 50 characters, inclusive.
- Each element of guitarNames will contain only uppercase letters ('A' - 'Z').
- All elements of guitarNames will be distinct.
{"GIBSON","FENDER", "TAYLOR"}
{"YNYYN", "NNNYY", "YYYYY"}
Returns: {"TAYLOR" }
You can play all the songs on the TAYLOR guitar.
{"GIBSON", "CRAFTER", "FENDER", "TAYLOR"}
{"YYYNN", "NNNYY", "YYNNY", "YNNNN"}
Returns: {"CRAFTER", "GIBSON" }
You can play all the songs, but you need 2 guitars to do it.
{"AB", "AA", "BA"}
{"YN", "YN", "NN"}
Returns: {"AA" }
You can only play the first song, so you buy guitar AA because it comes before AB alphabetically.
{"FENDER", "GIBSON", "CRAFTER", "EPIPHONE", "BCRICH"}
{"YYNNYNN", "YYYNYNN", "NNNNNYY", "NNYNNNN", "NNNYNNN"}
Returns: {"BCRICH", "CRAFTER", "GIBSON" }
{"XSWLEJGJFPJTAPNEVYLNVIBGPARTRGSZVMFTJOFAPVKVNCQAJA","JDIROLNQTU","FHV","MFTURTGHJYLLFWDIHZMSXDMUH","YYZCFHNVLFMVPSHZMRGDWMGYDBHUAQPZRRLHHQKICQXN","SFKPJZSCYTTZXTNSXOUJICOUBIW"}
{"YYNYNYYN","YYNYYYYY","YYYYYNNN","NYNYNYNN","YNNNYNNY","NNNNYNNY"}
Returns: {"FHV", "JDIROLNQTU" }
Submissions are judged against all 74 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class GuitarConcert with a public method vector<string> buyGuitars(vector<string> guitarNames, vector<string> guitarSongs) · 74 test cases · 2 s / 256 MB per case