Statistics

Problem Statement for "RoadSigns"

Problem Statement

A game that can be played while traveling by automobile is to try to find the 26 letters of the alphabet contained in road signs passed on the way. Start with the letter 'A'. If the letter 'A' is found in a road sign, look for the letter 'B'. Proceed through the consecutive letters of the alphabet in this manner until all of the letters are found. The following rules apply:

  • More than one letter can be found in the same sign.
  • Letters within a sign do not have to appear in alphabetic sequence.
  • Once a sign is passed it cannot be used again.
  • Once all the letters of the alphabet are found ending with the letter 'Z', the game ends.

Write a method that, given a String[] whose elements represent road signs in the order they are seen, examines each sign and returns the last letter found and the zero based index of the sign containing that last letter as a String in the form "cn" where 'c' represents the letter, and 'n' represents the index. If no letter is found, that is, the letter 'A' does not appear in the signs, or if there are no signs at all, return "" (the empty string).

Definition

Class:
RoadSigns
Method:
play
Parameters:
String[]
Returns:
String
Method signature:
String play(String[] signs)
(be sure your method is public)

Constraints

  • signs contains between 0 and 20 elements, inclusive.
  • the length of each element of signs is between 1 and 50 characters, inclusive.
  • each element of signs contains only uppercase letters ('A'-'Z'), digits ('0'-'9'), and the space character (' ').

Examples

  1. {}

    Returns: ""

  2. {"STOP","YIELD"}

    Returns: ""

  3. {"FALLING ROCK","SCHOOL BUS STOP AHEAD","SPEED LIMIT 15"}

    Returns: "E1"

    There are three signs. Start looking for the letter 'A'. The first sign, "FALLING ROCK", contains the letter 'A'. Now start looking for the letter 'B'. "FALLING ROCK" does not contain a 'B' so move on to the next sign. "SCHOOL BUS STOP AHEAD" does contain a 'B' . Now look for a 'C'. "SCHOOL BUS STOP AHEAD" also contains a 'C'. So look for a 'D', again found in "SCHOOL BUS STOP AHEAD". 'E' is also found. Now look for 'F'. "SCHOOL BUS STOP AHEAD" does not contain an 'F', so move on to the next sign. (Note that the 'F' contained in "FALLING ROCK" cannot be used because that sign has already been passed.) The third sign, "SPEED LIMIT 15", does not contain an 'F'. There are no more signs. The last letter found was the letter 'E' in "SCHOOL BUS STOP AHEAD" at index 1, so the method returns the result "E1".

  4. {"BRIDGE FREEZES BEFORE ROAD SURFACE","EXIT 8 HEBRON AVENUE"}

    Returns: "I1"

  5. {"A","B","C","D","E","F","G","H","I","J","K","L","M","X","Y","Z"}

    Returns: "M12"

  6. {"MIND THE GAP","WAY OUT","LOOK RIGHT"}

    Returns: "A0"

  7. {"ABCDEFGHIJKLMNOPQZ","RSTUVWXYZ","ABCDEXYZ","ABCFXYZ"}

    Returns: "Z1"

  8. {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T"}

    Returns: "T19"

  9. {"B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","A"}

    Returns: "A19"

  10. {"ZYXWVUTSRONMLKJIHGFEDCB0BCDEFGHIJKLMNOPQRSTUVWXYZ","ZYXWVUTSRONMLKJIHGFEDCB1BCDEFGHIJKLMNOPQRSTUVWXYZ","ZYXWVUTSRONMLKJIHGFEDCA1ACDEFGHIJKLMNOPQRSTUVWXYZ","ZYXWVUTSBONMLKJIHGFEDCB1BCDEFGHIJKLMNOPQBSTUVWXYZ","ZYXWRUTSBONMLKJIHGFEDCB1BCDEFGHIJKLMNOPQBSTURWXYZ","ZYVWRUTSBONMLKJIHGFEDCB1BCDEFGHIJKLMNOPQBSTURWVYZ","AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA","BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB","YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY","ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ","CCCCCCCCC Z 23 Z CCCCCC X C","XDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD","2222222222222222222 XXXXXXXX 22222222","2222222222222222222 33333333","222222ZA22222222222 4444444444444444444","2222222222222222222 555555 ZZZZZZZZ","ZZZZZZ 66ABCDEFG66666 6666666666 ZZZZZZ 6666666","77777777HIJKLMNOPQR777777777777777777777777777777","888888888888 STUVWXZ 8888888888888888888888888888","99999999 999999999999 99999999999 999999999 99999"}

    Returns: "X10"

  11. {"A","A"}

    Returns: "A0"

  12. {}

    Returns: ""

  13. {"ABCD","XYZ"}

    Returns: "D0"

  14. {"ABCDEFGHIJKLMNOPQZ","RSTUVWXYZ","ABCDEXYZ","ABCFXYZ"}

    Returns: "Z1"

  15. {"HODAK","CEBRA","ZEL"}

    Returns: "C1"

  16. {"ABCDE","CDE","F","GHIJK"}

    Returns: "K3"

  17. {"ABC","XYZ","DEF","ABCDEFG"}

    Returns: "G3"

  18. {"ABCDEFGHIJKLMNOPQRSTUVWXYZ","DBEXZ","FXZ"}

    Returns: "Z0"

  19. {"A1B"}

    Returns: "B0"

  20. {"BAD"}

    Returns: "B0"

  21. {"ABCD","GHIJKL","EFGH","KLMNOP"}

    Returns: "H2"

  22. {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O"}

    Returns: "O14"

  23. {"ABCDEFGHIJKLMNOPQZ","RSTUVWXYZ","ABCDEXYZ","ABCFXYZ"}

    Returns: "Z1"

  24. {"ABCDEFGHIJKLMNOPQRSTUVWXYZ","ZZZA","AZ"}

    Returns: "Z0"

  25. {"MAN THIS IS BAD"}

    Returns: "B0"

  26. {"DAB","C"}

    Returns: "C1"

  27. {"ABD","CXY","KKK","HHH","IBC"}

    Returns: "C1"

  28. {"DCBA","ZYX"}

    Returns: "D0"

  29. {"A","C","B"}

    Returns: "B2"

  30. {"BAC","DK","XYZ","ABCD"}

    Returns: "D1"

  31. {"B","B","B","B","B","B","B","B","B","B","B","B","B","B","B","B","B","A"}

    Returns: "A17"

  32. {"BRAEBURN","CEDAR","POSH"}

    Returns: "E1"

  33. {"I AM A BODY","OSTC MY JUNE"}

    Returns: "C1"

  34. {"BCDEF","GHIJKL","ABCZ"}

    Returns: "C2"

  35. {"ABC","DEFGH","ACDELLMNOP","IJKL"}

    Returns: "L3"

  36. {}

    Returns: ""

  37. {"ROAD BAD"}

    Returns: "B0"

  38. {"B","B","B","B","B","B","B","B","B","B","B","B","B","B","B","B","A"}

    Returns: "A16"

  39. {}

    Returns: ""


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: