A page in an address book contains two addresses. Each address is written as a string of lowercase letters and digits.
Find the length of the longest sequence of characters shared by both addresses. This sequence contains matching characters that appear in the same order in both addresses. You may skip characters, but you cannot rearrange the characters you keep. The kept characters do not need to be next to one another.
AddressSimilarityAnalyzer
AddressSimilarityAnalyzer()
public int findLongestSharedSequence(String firstAddress, String secondAddress)
firstAddress is the first address.secondAddress is the second address.0.1 ≤ firstAddress.length(), secondAddress.length() ≤ 1,000firstAddress and secondAddress contain only lowercase English letters and digits.firstAddress and secondAddress are non-null.m = firstAddress.length() and n = secondAddress.length().O(mn) time.O(mn) additional space or less.The method returns only the greatest possible length. If several matching sequences have this length, the returned integer is still the same.
findLongestSharedSequence( firstAddress = "12parkstreet", secondAddress = "12street")
Output: 8
All eight characters of "12street" appear in the same order in both addresses.
findLongestSharedSequence( firstAddress = "45northroad", secondAddress = "45southroad")
Output: 9
The nine characters in "45othroad" can be kept in the same order in both addresses.
findLongestSharedSequence( firstAddress = "pine", secondAddress = "42road")
Output: 0
The two addresses have no character in common.