Problem Statement
You are given two
For example, "BIGTOP" and "TOPCODER" have an overlap of length 3, with the substring "TOP".
On the other hand, the strings "HELLO" and "GOODBYE" have an overlap of length 0.
Return the length of the maximum overlap of the two strings you are given.
Definition
- Class:
- StringOverlap
- Method:
- largestOverlap
- Parameters:
- String, String
- Returns:
- int
- Method signature:
- int largestOverlap(String s1, String s2)
- (be sure your method is public)
Constraints
- s1 and s2 will each contain between 1 and 50 uppercase ('A'-'Z') characters, inclusive.
Examples
"TOPCODER"
"BIGTOP"
Returns: 3
This is an example mentioned in the problem statement.
"HELLO"
"GOODBYE"
Returns: 0
Also an example from the problem statement.
"CODERTOP"
"TOPCODER"
Returns: 5
Notice that we can get an overlap regardless of which string we take first, however, one is longer (5) than the other (3).
"STRINGA"
"STRINGB"
Returns: 0
The strings are almost identical, but putting one after the other, there's no overlap.
"STRING"
"STRING"
Returns: 6
The strings completely overlap in this case.
"ASTRING"
"STRING"
Returns: 6
"BIGTOP"
"TOPCODER"
Returns: 3