Write a method called indexMap that takes a list of strings as a parameter and that returns a map that associates each string from the list to a list of indexes at which that string occurs. For example, if a variable called list stores the following:
[to, be, or, not, to, be]
then the call indexMap(list) should return the following map:
{be=[1, 5], not=[3], or=[2], to=[0, 4]}
Notice that each string from the original list maps to a list of indexes. For example, the string "to" appeared at index 0 and 4 in the original list, so it maps to a list with the values 0 and 4. The map returned by your method should be ordered alphabetically and the lists that each string maps to should have indexes in increasing order, as in the example.
Your method should construct the new map and each of the lists contained in the map and can construct iterators but should otherwise not construct any new data structures. It should also not modify the list of words passed as a parameter and it should be reasonably efficient.