Problem Statement
Any letters beyond these requirements are to be excluded, so if the decree specifies k comparisons then the new alphabet will contain the first k+1 lowercase letters of the current alphabet.
Create a class Alphabet that contains the method firstAlpha that takes the decree as input and returns the new alphabet as a String that is first alphabetically among all alphabets that conform to the decree. Specifically, if 2 alphabets conform to the decree, choose the one with the lower character in the first position in which they differ.
Definition
- Class:
- AlphaWord
- Method:
- firstAlpha
- Parameters:
- String
- Returns:
- String
- Method signature:
- String firstAlpha(String decree)
- (be sure your method is public)
Constraints
- decree contains between 1 and 25 characters, inclusive.
- Each character in decree is the uppercase letter 'B' or 'A'.
Examples
"BAA"
Returns: "adcb"
'a' Before 'b', 'b' After 'c', and 'c' After 'd' have been decreed, so possibilities are "adcb", "dacb", "dcab"."AAAA"
Returns: "edcba"
"edcba" is the only alphabet that conforms."BBAA"
Returns: "abedc"
all the alphabets that satisfy this are: "edabc", "eadbc", "aedbc", "eabdc", "aebdc", and "abedc". Of these, the first is "abedc"."BABABABABABABABABABABABAB"
Returns: "acbedgfihkjmlonqpsrutwvyxz"