log is a list of words in the order the events happened. Given two words left and right, find the smallest distance between an entry of left and an entry of right, where positions i and j are |i - j| apart.
The words left and right may be the same, in which case you need two **different** entries of that word. The required entries are guaranteed to exist (at least two of them when the words are equal).log=["login", "view", "buy", "view", "logout"], left="buy", right="view" → 1
"buy" is at position 2 and "view" at 1 and 3, so the closest pair is 1 apart.
log=["view", "buy", "login", "view", "view"], left="view", right="view" → 1
The words coincide, so look for two different "view" entries: positions 3 and 4 are adjacent.
log=["pay", "ship", "ship", "ship", "pay"], left="pay", right="pay" → 4
The two "pay" entries are at positions 0 and 4, which are 4 apart.
left and right occur in log; if they are equal, the word occurs at least twicelog=["login", "view", "buy", "view", "logout"], left="buy", right="view"
1
Run checks the first 3 tests in your browser. Submit checks all 99 tests on the server, hidden ones included.