Statistics

Problem Statement for "StringOverlap"

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.

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

  1. "TOPCODER"

    "BIGTOP"

    Returns: 3

    This is an example mentioned in the problem statement.

  2. "HELLO"

    "GOODBYE"

    Returns: 0

    Also an example from the problem statement.

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

  4. "STRINGA"

    "STRINGB"

    Returns: 0

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

  5. "STRING"

    "STRING"

    Returns: 6

    The strings completely overlap in this case.

  6. "ASTRING"

    "STRING"

    Returns: 6

  7. "BIGTOP"

    "TOPCODER"

    Returns: 3


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: