If I asked you to read the following lines aloud
It was the best of times, it was the worst of times, it was the
the age of wisdom, it was the age of foolishness, it was the
epoch of belief, it was the epoch of incredulity, ...
there is a very good chance that you would say "it was the age of wisdom"
instead of "it was the the age of wisdom". This is a common typing
error that can be fiendishly difficult to spot.
After making this error one too many times, you have decided to build a tool to detect
such errors automatically. Given a String[] lines, you are to return
the zero-based index of the first line whose last word is the same as the first word on the
next line, or -1 if there is no such line. Each line contains one or more words separated by spaces. Words are composed
of uppercase and lowercase letters ('A'-'Z' and 'a'-'z').
Two words are considered the same if they are exactly equal, including
capitalization.
|