Problem Statement | |||||||||||||
In this problem your goal is to convert a description of how a guitar chord is played to its name. For the purpose of this problem we will only consider major and minor chords.
Musical notes are given the following 12 names, in ascending order:
The difference between two succesive notes is called a half-step. The order of notes is cyclic. That is, the note one half-step higher than B is again C, and the note two half-steps lower than C is A#. Notes that are a multiple of 12 half-steps apart have the same name, and for our purposes we will consider them equivalent. In this problem we will consider a six-string guitar with standard tuning. The six strings of such a guitar are tuned to the following notes, in order: E, A, D, G, B, E. (Guitar players, please note that the order used starts with the lowest string.)
If you play an open string, you will hear the corresponding note. For example, if you play the A string, you will hear the note A.
You will be given a guitar chord encoded as a int[] chord with six elements, each of them describing one string of the guitar in the order given above. For each string we are given the fret where to hold it down. The value 0 represents an open string that plays the original note, and the special value -1 is used for a string that is not played in the chord.
For example, suppose that chord = {-1, 3, 2, 0, 1, 0}.
The above chord contains three distinct notes: C, E, and G. This chord is called the "C Major" chord. For any note X, the "X Major" chord is formed by three distinct notes. It can be obtained from the "C Major" chord by shifting all three notes by the same number of steps so that C becomes X. For example, if we shift the notes (C,E,G) by three steps, we get the notes (D#,G,A#). These three notes form the "D# Major" chord. Similarly, the chord "C Minor" is formed by the notes C, D#, and G, and all other minor chords are shifts of this chord. Given the int[] chord, decide whether it is one of the 12 major or one of the 12 minor chords, as defined above. If it is one of these chords, return its name as a String ("X Major" for major chords, "X Minor" for minor chords). If the chord represented by chord is not one of our chords, return an empty String. | |||||||||||||
Definition | |||||||||||||
| |||||||||||||
Notes | |||||||||||||
- | When classifying a chord the only thing that matters is the set of notes played. The number of times a note is played does not matter as long as each of the required notes is played at least once. | ||||||||||||
Constraints | |||||||||||||
- | chord will contain exactly 6 elements. | ||||||||||||
- | Each element of chord will be between -1 and 12, inclusive. | ||||||||||||
Examples | |||||||||||||
0) | |||||||||||||
| |||||||||||||
1) | |||||||||||||
| |||||||||||||
2) | |||||||||||||
| |||||||||||||
3) | |||||||||||||
| |||||||||||||
4) | |||||||||||||
| |||||||||||||
5) | |||||||||||||
| |||||||||||||
6) | |||||||||||||
| |||||||||||||
7) | |||||||||||||
|