Connection Status:
Competition Arena > StringOverlap
Rookie SRM 18 · 2022-10-10 · by erinn · String Manipulation
Class Name: StringOverlap
Return Type: int
Method Name: largestOverlap
Arg Types: (string, string)
Problem Statement

Problem Statement

You are given two Strings, s1 and s2. Two strings have an overlap if the last few characters of one string are identical to the first few characters of the other string.

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.

Constraints

  • s1 and s2 will each contain between 1 and 50 uppercase ('A'-'Z') characters, inclusive.
Examples
0)
"TOPCODER"
"BIGTOP"
Returns: 3

This is an example mentioned in the problem statement.

1)
"HELLO"
"GOODBYE"
Returns: 0

Also an example from the problem statement.

2)
"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).

3)
"STRINGA"
"STRINGB"
Returns: 0

The strings are almost identical, but putting one after the other, there's no overlap.

4)
"STRING"
"STRING"
Returns: 6

The strings completely overlap in this case.

Submissions are judged against all 7 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class StringOverlap with a public method int largestOverlap(string s1, string s2) · 7 test cases · 2 s / 256 MB per case

Submitting as anonymous