Problem Statement
A xylophone is a musical instrument that consists of a sequence of wooden bars. In order to make a sound, you have to strike one of the bars by a mallet.
For the purpose of this problem we will assume that our xylophone has exactly 50 bars. The bars are numbered from 1 to 50 in the order from the left to the right.
There are 7 notes: A, B, C, D, E, F, G. Each bar of our xylophone plays one of these notes. The notes repeat periodically. When you play the bars from the left to the right, you will hear the following sequence of notes: A,B,C,D,E,F,G,A,B,C,D,E,F,G,A,B,C,...
In other words: bar 1 produces the note A, bar 2 plays B, bar 3 plays C, ..., bar 7 plays G, and then the sequence of notes starts repeating: bar 8 plays the note A again, bar 9 is B, and so on.
You have hit a sequence of bars.
You are given their numbers in the
Definition
- Class:
- Xylophone
- Method:
- countKeys
- Parameters:
- int[]
- Returns:
- int
- Method signature:
- int countKeys(int[] keys)
- (be sure your method is public)
Constraints
- keys will contain between 1 and 50 elements, inclusive.
- Each element of keys will be between 1 and 50, inclusive.
Examples
{1,8,3}
Returns: 2
If you hit the keys 1,8,3, you have played the notes A,A,C. This means you have hit two distinct notes: A and C.
{7,3,2,4,1,5,6}
Returns: 7
In this case you have played 7 distinct notes, each of them exactly once.
{1,8,15}
Returns: 1
Although these are all distinct keys, these keys all have the same note, so they are counted as one.
{25,1,17,9,8}
Returns: 4
{11,11,11,11,11,11,11,11,11,11,11}
Returns: 1
{50,10,20,30,11,30,24,38,5,2,9}
Returns: 6
{14,38,14,15,23,21}
Returns: 4
{45,35,41,14,18,18,39,14,5,3,31,10,42,7,3,42}
Returns: 5
{13,29,43,22,34,37,50,34,11,9,21,22,32,39,1,22,2,25,46,26,16,6,21,40,7,10,29,25,50,47,43,24,38,25,7,29,31,48,30,14,41,3,34,27,17,49,16}
Returns: 7
{3,10,6,4,1,13,1,8,2,41,5,24,1,42,2,1,39,2,5,5,2,2,25,8,1,3,48,1,22,19,44,37,3,35,1,6,5,16,1,1,2,42,3,10,6,24,4}
Returns: 7
{1,30,33}
Returns: 3
{31,6,5,2,14,21,12,1,4,24,6,1,2,1,23,28,16,36,1,2,14}
Returns: 7
{6}
Returns: 1
{26,9,38,45,1,30,34,6,21,45,41,23,17,16,4,12,40,50,8,7,8,17,18}
Returns: 7
{16,11,34}
Returns: 3
{36,3,37,10,8,21,9,41,48,14,34,23,2,6,36,4,18,40,8,7,18,20,11,2,22,23,9}
Returns: 7
{42,13,39,14,34,17,49,17,40,47,15,1,21,21,3,34,47,18,45,29,44,15,12,31,23,10,25,42,23,30,20,10,15,6,36,45,47,45,2,7,44,36,37,46,7,40}
Returns: 7
{5,40,9,44,8,18,7,18,37,10,8,10,16,9,17,15,25,39,17,44,15,14,32,46,1,5,17,50,42,14,48,36,8,34,34,17,17}
Returns: 7
{46,34,2,16,7,1,26,38,5,39,1}
Returns: 7
{14,43,28,3,27,40,28,37,40,29,6,28,25,22,5,13,14,32,22,26,19,13,2,11,48,27,40,25,45,36,49,39,33,50,39,32,22,44,44,31,21,29,26}
Returns: 7
{1}
Returns: 1
{14,50,30,19}
Returns: 4
{50,49,4,11,46,4,10,11,41,19}
Returns: 6
{33,25,17,20,43,27,32,33,21,13,48,6,15,30,33,6,13,31,7,41,36,23,38,15,49,23,25,4,13,22,42,49,8,23,35,49,29,11,35,11,27,6,21,8,48}
Returns: 7
{12,38,8,48,43,5,36,4,18,41,20,29,12,22}
Returns: 5
{11,23,37,14,45,10,4,13,25,29,13,35,11,21}
Returns: 6
{27,5,25,5,1,28,11,49,2,12,15,4,41,32,40,39,29,41,39}
Returns: 6
{42,6,22,27,7,23,8,32,3,1,29,29,39,26,24,43,45,43,35,6,48,33,15,45,10,8,47,8,27,10,19,2,31,14,24,26,44,6,19,8,25,45,39,14,2,30}
Returns: 7
{35,26,19,1,45,37,23,45,44,39,8,5,20,48,30,28,5,50,20,11,44,4,25,9,4,8,37,45}
Returns: 7
{34,35,31,27,45,21,36,24,2,45,21,22,4,45,8,49}
Returns: 6
{41,41,50,48,14,34,38,18,17,45,20,21}
Returns: 5
{33,27,12,39,5,9,25,34,20,17,12,43,2,37,22,40,14,13,7,29,7,21,8,2,9,22,7,29,29,10,48,42,32,13,3,29,48,23,43,20,37,50,30,15,25}
Returns: 7
{26,2,47,20,28,10,5,34,29,33,14,33,1,28}
Returns: 6
{46,10,34,31,14,20,9,5,34,12,8,40,29,37,33,34,6,19,38,13,4,41,37,24,45,10,9,48,18,43,39,31,45,30,22,1,42}
Returns: 7
{40,21,21,2,37}
Returns: 3
{30,42,45,9,11,13,9,46,9,11,39,26,22}
Returns: 7
{2,9,16,23,16}
Returns: 1
{19,40,23,6,48,36,7,17,9,38,22,43,46,40,15,1,37,33,35,49,5,39,7,23,37,33,19,27,32,12,41,10}
Returns: 7
{20,1,3,6,19,29,42,8,3,2,3,1,14,1,3,4,3,4,22,38,2,3,1,33,12,9,4,32,40,2,4,7,7,2,4,1,3,5,1,5,6,17,1,2,36,3,4}
Returns: 7
{14,5,30,1,46,19,40,38,34,38,12,4,15,30,20,3,50,43,6,11,3,32,44,7,33,23,40,16,37,27,31,30,34,14,47,15,34}
Returns: 7
{46,20,31,1,2,4,1,3,43,1,13,8,7,4,1,32,3,5,6,1,5,10,2,6,11,15,22,19,4,9,36,1,1}
Returns: 7
{2,7,4,3,23,1,1,2,3,36,4,26,8,9,10,46,10,5,1,1,8,5,2,1,1,13}
Returns: 7
{3,11,24,18,3,17,25,3,3,24,24,18,17,4,3,25,4,17,18,24,3,17,25,3,4,10,3,3,4,10,10,10,18,4,17,10,11,24,11,25,11,18,25,11,25,4,18,24,11,17}
Returns: 2
{24,18,17,25,3,18,11,4,18,18,11,3,4,4,18,4,17,24,10,10,3,4,24,11,17,18,25,24,18,25,4,17,17,3,4,3,10,17,24,24,17,10,4,4,25,18,3,4,3,3}
Returns: 2
{1, 8 }
Returns: 1
{1, 2, 3, 4, 5, 6, 7 }
Returns: 7
{8, 3 }
Returns: 2
{1, 2, 3, 4, 5, 6, 7, 8, 9 }
Returns: 7
{14, 7 }
Returns: 1
{1, 8, 15 }
Returns: 1
{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }
Returns: 7