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
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".
"BABAAA"
Returns: "acbgfed"
"A"
Returns: "ba"
"B"
Returns: "ab"
"BAAAAAAAAAAAAAAAAAAAAAAAA"
Returns: "azyxwvutsrqponmlkjihgfedcb"
"AAAAAAAAAAAAAAAAAAAAAAAAA"
Returns: "zyxwvutsrqponmlkjihgfedcba"
"BBBBBBBBBBBBBBBBBBBBBBBBB"
Returns: "abcdefghijklmnopqrstuvwxyz"
"AABBAABBAABBB"
Returns: "cbadgfehkjilmn"
"BBBBBBBBBBBBAAAAAAAAAAAA"
Returns: "abcdefghijklyxwvutsrqponm"
"BABABABABABABABABABABABAB"
Returns: "acbedgfihkjmlonqpsrutwvyxz"
"BABBAAABBBB"
Returns: "acbdhgfeijkl"
"BBBBBBBA"
Returns: "abcdefgih"
"AAAAAAB"
Returns: "gfedcbah"
"AAAAAAAAAAAAAAAAAAAAAAAAA"
Returns: "zyxwvutsrqponmlkjihgfedcba"
"ABBABAABBAABAABAABBBA"
Returns: "bacedhgfilkjonmrqpstvu"
"BBAA"
Returns: "abedc"
"BABABABABABABABABABABAB"
Returns: "acbedgfihkjmlonqpsrutwvx"
"BABABABA"
Returns: "acbedgfih"
"ABBA"
Returns: "baced"
"BABABABABABABABABABABABAB"
Returns: "acbedgfihkjmlonqpsrutwvyxz"
"ABBABABBAAABB"
Returns: "bacedgfhlkjimn"
"BBBBBBBBBBBBBBBBBBBBBBBBB"
Returns: "abcdefghijklmnopqrstuvwxyz"
"AABBA"
Returns: "cbadfe"