Write a function named commonFirstLetters
that accepts a reference to a Vector
of strings as a parameter, and returns a Set
of characters (char
values) in alphabetical order.
Your function should examine the strings in the vector passed and return a set of all first characters that occur more than once, in lowercase.
In other words, if two or more strings in the vector begin with a particular character (case-insensitively), that letter should be part of the set that you return.
Consider a Vector
called list
containing the following elements:
{"Julie", "hi", "how", "is", "He", "Marty!", "this", "morning?", "fine.", "?huh?", "HOW", "I"}
One word in the list begins with 'f', four begin with 'h', two begin with 'i', one begins with 'j', two begin with 'm', one begins with 't', and one begins with '?'.
Therefore the set you return should contain the following elements in alphabetical order:
{'h', 'i', 'm'}
If no first character occurs 2 or more times, return an empty set.
If any of the vector's elements is an empty string, it does not have a first letter, so it should be excluded from your computation.
Obey the following restrictions in your solution:
- You may create only up to two (2) new data structures of your choice (vector, stack, queue, set, map, etc.) as auxiliary storage.
(You can have as many simple variables as you like.)
- You should not modify the contents of the list passed to your function.