TopcoderArchiveVisit Topcoder
SRM27 Aug 2001
SRM 26

CompareSubstring

Problem statement, definition, constraints, and public examples.

Problem Statement

Class name: CompareSubstring
Method name: findLongest
Parameters: String,String
Returns: int


Find the longest common substring between the two passed Strings.  The
substring can be any part of the String, including the entire String.  If there
is no common substring, return 0.  The search IS case sensitive ('x' != 'X').


Here is the method signature (Be sure your method is public):
int findLongest(String s1, String s2);


INPUT:
Both input Strings will contain between 1 and 50, inclusive, letters (a-z,
A-Z), and/or spaces.


OUTPUT:
The length of the longest common substring between the two Strings.


EXAMPLES:

Input: "abcdef" "cdofhij"
Since the longest substring present in both words is "cd", the output is 2.


Input: "TWO" "FOUR"
Output: 1


Input: "abracadabra" "open"
Output: 0


Input: "Hey This java is hot" "Java is a new paradigm"
Output: 7 (longest substring - "ava is ")

Definition

Class:
CompareSubstring
Method:
findLongest
Parameters:
String, String
Returns:
int
Method signature:
int findLongest(String param0, String param1)
(be sure your method is public)

Constraints

    Examples

      No public sample cases were explicitly marked for this problem in the original data.

      Back to all problems