Problem Statement
We want to specify the order in which the cars should be moved. The order of cars must allow each car to be moved just once all the way to its unloading position where it will remain.
The cars are each named with a lowercase letter, and their destinations with the same letter but in uppercase. The positions of the cars and of their destinations are given by a sequence of letters that is regarded as circular by wrapping around the ends. So, for example, "BACacb" describes a situation in which going clockwise around the track we encounter B, A, C, a, c, b, and then return back to B. Here there are 3 different orders in which the cars could be moved to their destinations: 'a' then 'c' then 'b', 'a' then 'b' then 'c', or 'b' then 'a' then 'c'.
Create a class CircleOrder that contains a method firstOrder that is given the
original positions in a
If there is more than one order possible, give the one that comes first alphabetically. If no order is possible, your method should return the 4-letter String "NONE".
Definition
- Class:
- CircleOrder
- Method:
- firstOrder
- Parameters:
- String
- Returns:
- String
- Method signature:
- String firstOrder(String circle)
- (be sure your method is public)
Constraints
- circle will contain between 2 and 50 characters, inclusive.
- Each character will be a letter, 'a'-'z' or 'A'-'Z'.
- No character will appear more than once.
- If a letter appears in circle, it will appear both in uppercase and in lowercase.
Examples
"BACacb"
Returns: "abc"
This is the example given above. "abc" comes alphabetically before the other two choices, "acb" and "bac".
"ABCacb"
Returns: "NONE"
We cannot move car 'c' first. If we move 'a' first, then we can never move 'b' to 'B', but if we move 'b' first we can never move 'a' to 'A'.
"XYxPyp"
Returns: "xyp"
"BDAdCacb"
Returns: "bdac"
"abBcCdDeEfghFGHA"
Returns: "abcdehgf"
"BDdacAbC"
Returns: "bcad"
"acAC"
Returns: "ac"
"wXWBbx"
Returns: "bwx"
"cCdDeEFGfgHhIiJjKklLmnMNoOpPQqRr"
Returns: "cdefghijklnmopqr"
"CrcdDeEFGfgHhIiJjKklLmnMNoOpPQqR"
Returns: "defghijklnmopqrc"
"mnMNoOpPQqRCrcdDeEFGfgHhIiJjKklL"
Returns: "defghijklnmopqrc"
"aCbAcB"
Returns: "NONE"
"abCAcB"
Returns: "cab"
"DOGNAPHERZYLBCFIJKMQdognapherzylbcfijkmq"
Returns: "dognapherzylbcfijkmq"
"QOGNAPHERZYLBCFIJKMDqognapherzylbcfijkmd"
Returns: "dmkjifcblyzrehpangoq"
"DadAVvLl"
Returns: "NONE"
"ogGRUXsHDfqbuxAhOrBElwSWvaedLFQV"
Returns: "NONE"
"iGEecqVYCSdQPsgUpmuTMbBXvJjxyWItwD"
Returns: "NONE"
"uaKkEQftFNZRUqzTWwrOeonA"
Returns: "NONE"
"JpxUCruFQaloSjmiwGOtEAzZTPRIqeMfYLNyncHXhgsW"
Returns: "NONE"
"uPRJqBYfMeLQtdDlEhwkcsCVKUSmjrTzpNHyFnvWbZ"
Returns: "NONE"
"xTqKrGRtXEQekg"
Returns: "NONE"
"TmNPUjpqvnlBfVOioItZuWbQLARaJDMkFKrzcwdC"
Returns: "NONE"
"hmVlSsvLkMHK"
Returns: "NONE"
"yNkDWVZrBaKzpmGvbqJdYFQRPgjSiMufnsTUtwXxAI"
Returns: "NONE"
"cCdDeEfFgGiIjJmMoOqQrRtTuUvVwWxXyYzZ"
Returns: "cdefgijmoqrtuvwxyz"
"aAbBcCdDeEgGhHiIjJkKmMqQrRsStTuUwWyY"
Returns: "abcdeghijkmqrstuwy"
"bBhHiIlLmMnNpPqQrRtTuUvVwWzZ"
Returns: "bhilmnpqrtuvwz"
"KGhJjgIkiqHQ"
Returns: "NONE"
"uvVPpU"
Returns: "puv"
"ucCFUf"
Returns: "cfu"
"zoWmAFZMaOgwfG"
Returns: "NONE"
"UuPAsapRtTSgrG"
Returns: "NONE"
"LqQOFolf"
Returns: "NONE"
"iFkpzPZIKf"
Returns: "NONE"
"gQhZHzGq"
Returns: "NONE"
"zVAaZv"
Returns: "NONE"
"QprJZjiYIfPFqzRy"
Returns: "NONE"
"qILRgzZQOGojJril"
Returns: "NONE"
"EoOIeWiAaw"
Returns: "NONE"
"jYyboOJmBM"
Returns: "NONE"
"cNCGng"
Returns: "NONE"
"vAOElopLVIePai"
Returns: "NONE"
"uHULhl"
Returns: "NONE"
"XrSWRUmswzMZxu"
Returns: "NONE"
"kKiI"
Returns: "ik"
"kdSsJKjD"
Returns: "jkds"
"JpjSPs"
Returns: "spj"
"uHULlh"
Returns: "luh"
"XYxPypAabcBCdDeE"
Returns: "acbdexyp"
"BACacb"
Returns: "abc"
"AaBbCcDdEeFfGgHhJjKkLlPpOoIiUuYyTtRrWwQqZzXxVvNnMm"
Returns: "abcdefghijklmnopqrtuvwxyz"