Statistics

Problem Statement for "AlphDistn"

Problem Statement

PROBLEM STATEMENT
Alphabetic distance between two characters is defined as the positive
difference between their numeric positions in the alphabet. For example, the
alphabetic distance between 'A' and 'B' is 1; the alphabetic distance between
'A' and 'C' is 2, and so on; the alphabetic distance between 'A' and 'Z' is 25.
Given an int N and a String S, find the longest substring of S such that no
pair of characters should exist in the substring such that the alphabetic
distance between them is greater than N (note: the pair of characters do not
have to be adjacent).  When there are multiple substrings of the same length
that all satisfy the alphabetic distance condition, your method should return
the one that occurs earlier in the input string S.

DEFINITION
Class name: AlphDistn
Method name: longest
Parameters: int, String
Return type: String
Method signature (be sure your method is public): String longest (int N, String
S);

TopCoder will ensure the validity of the inputs. Inputs are valid if all of the
following criteria are met:
- S has between 1 and 50 characters, inclusive,
- S contains only uppercase letters 'A' through 'Z', inclusive,
- N is in the range from 0 to 25, inclusive.

EXAMPLES
1. When N= 0 and S="TOPCODER", your method should return "T".
2. When N= 4 and S="TOPCODER", your method should return "OP".
3. When N=25 and S="TOPCODER", your method should return "TOPCODER".
4. When N= 1 and S="ABCD", your method should return "AB".
5. When N= 2 and S="ABCDDCBAABCDDCBAWXYZZXYWWYXZZXYWWYXZZXABCDDCBA", your
method should return "BCDDCB".
6. When N= 3 and S="ABCDDCBAABCDDCBAWXYZZXYWWYXZZXYWWYXZZXABCDDCBA", your
method should return "WXYZZXYWWYXZZXYWWYXZZX".

Definition

Class:
AlphDistn
Method:
longest
Parameters:
int, String
Returns:
String
Method signature:
String longest(int param0, String param1)
(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: