Statistics

Problem Statement for "ConsecLet"

Problem Statement

PROBLEM STATEMENT
Certain words in the English language contain strings of consecutive
alphabetical letters in them.  For example, the word "UNDERSTUDY" contains the
substring "RSTU", where these four letters appear consecutively in the
alphabet.  Write a method where given a String returns the length of the
longest substring consisting of only letters that appear consecutively in the
alphabet.


DEFINITION
Class Name:  ConsecLet
Method Name:  bestAlpha
Parameters:  String
Return Type:  int

Method Signature (be sure your method is public):  int bestAlpha (String word);

NOTES
- The empty String ("") has 0 consective alphabetical letters in it.  See
example 4.
- If a String only has trivial substrings of this sort (i.e. only one
consecutive alphabetical letter) return 1.  For a non-empty String, the return
value must be at least 1.  See example 3.
- The alphabet does not "wrap".  See example 5.

TopCoder will ensure that:
- word is between 0 and 50 characters (inclusive).
- Only the uppercase letters 'A' through 'Z' appear in word.  No lowercase
letters, spaces, or other punctuation will appear in word.

EXAMPLES
1.  word = "UNDERSTUDY"
"RSTU" is the longest substring of consecutive alphabetical letters.
Return 4.

2.  word = "GYMNOPLAST"
"MNOP" is the longest substring of consecutive alphabetical letters.
Return 4.

3.  word = "HELLO"
Looking at the substrings of length 1 one at a time, "H", "E", "L", "L",
"O", each has only one letter appearing consecutively in the alphabet.  Return 1.

4.  word = ""
    There are no proper substrings of this word.  Return 0.

5.  word = "UNANALYZABLE"
The substring "YZAB" is contained in word, but the alphabet does not
"wrap".  "YZ" and "AB" are the longest substrings of consecutive letters, each
has a length of 2.  Return 2.

6.  word = "CALMNESS"
"LMN" is the longest substring of consecutive alphabetical letters.  Return
3.

7.  word = "SYNOPSIS"
"NOP" is the longest substring of consecutive alphabetical letters.  Return
3.

8.  word = "CBA"
    Consecutively decreasing letters do not count.  Return 1.

Definition

Class:
ConsecLet
Method:
bestAlpha
Parameters:
String
Returns:
int
Method signature:
int bestAlpha(String param0)
(be sure your method is public)

Constraints

    Examples


      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: