Write InvertedIndex. The first line is n; the next n lines are the text. Build a TreeMap<String, TreeSet<Integer>> mapping each word (lower case, letters only) to the set of line numbers where it occurs. Print the number of distinct words and the word that appears on the most lines (the first in alphabetical order on a tie).
Each remaining line is a query of one or more words: print the lines that contain all of them (retainAll), or not found.
For the input
4
The quick brown fox
jumps over the lazy dog
The dog barks
A quick red fox
fox
the dog
quick fox
cat
the cat
the program prints
Distinct words: 11
On the most lines: the [1, 2, 3]
fox: lines [1, 4]
the + dog: lines [2, 3]
quick + fox: lines [1, 4]
cat: not found
the + cat: not found