Statistics

Problem Statement for "WalkingHome"

Problem Statement

Johnny has to walk home from school, and wants to map out the best route to take, so that he has to cross as few streets as possible.

You are given a String[] map that maps the roadway layout of Johnny's town. The location of Johnny's school is designated with a 'S' character, and the location of Johnny's home is designated with a 'H' character. North-South roads are denoted by a '|' character, while East-West roads are denoted by a '-' character. Intersections, which can never be crossed, are indicated by '*' characters. Fences, indicated by a 'F' character, can also never be crossed. All other areas are indicated by '.' characters; Johnny can walk freely over these areas.

For maximum safety, Johnny may only walk directly across a road, perpendicular to the traffic, never diagonally. All of Johnny's movements, onto and off of a road, and walking around town, should be in one of the four cardinal directions. Johnny may, however, cross roads that are multiple lanes wide, and doing so only counts as a single crossing. Two or more adjacent || characters are always considered to be a single road, and this works similarly for '-' characters that appear adjacent vertically.

For instance, the following requires only a single crossing, since it's a single two-lane road:

S.||.H

Also, a situation such as the following leaves Johnny with no safe way to walk home, since he cannot cross the road diagonally, and can only step onto and off a road in a direction perpendicular to the road:

S||
||H

Also notice that because Johnny can never move diagonally, in the following case, Johnny cannot get home:

S.F
.F.
F.H

You are to return an int indicating the fewest number of times Johnny must cross the street on his way home. If there is no safe way for Johnny to get home, return -1.

Definition

Class:
WalkingHome
Method:
fewestCrossings
Parameters:
String[]
Returns:
int
Method signature:
int fewestCrossings(String[] map)
(be sure your method is public)

Notes

  • If a street is more than one unit wide, it still only counts as a single crossing.

Constraints

  • map will contain between 1 and 50 elements, inclusive.
  • Each element of map will contain between 1 and 50 characters, inclusive.
  • Each element of map will contain only the characters '.', '-', '|', '*', 'F', 'S', 'H'.
  • There will be exactly one occurrence each of 'S' and 'H' in map.
  • Each element of map will contain the same number of characters.

Examples

  1. {"S.|..", "..|.H"}

    Returns: 1

    Here, Johnny lives right across the street from the school, so inevitably, he's crossing the street once to get home.

  2. {"S.|..", "..|.H", "..|..", "....."}

    Returns: 0

    Similar to above, but since the road has a dead end (maybe even a cul-de-sac at the end), Johnny can get home without actually having to cross the road.

  3. {"S.||...", "..||...", "..||...", "..||..H"}

    Returns: 1

    Notice here that even though it's a 2-lane highway, it only counts as a single crossing.

  4. {"S.....", "---*--", "...|..", "...|.H"}

    Returns: 1

    Here, Johnny could go down across the street and then right across another street to his house. However, if he first goes to the right before crossing down, he will only cross 1 street.

  5. {"S.F..", "..F..", "--*--", "..|..", "..|.H"}

    Returns: 2

    Similar to above, but because there's a fence around the school, Johnny has no choice but to cross twice.

  6. {"S|||||||" ,"--------" ,"|||....." ,"|||....." ,"|||....H"}

    Returns: -1

  7. {"............|....","............|....","...F........|....","...F........|....","..FF........|....","..FF........|....","..FF........|....","..F.........|.FFF","..F.........|...|","..F.........|...|","..F.........|...|","..F.........|...|","..F.FFFFFFFF|FFF|","..F.........|...|","..F.........|...|","..F.........|....","..F.........|....","..F.........|....","..F.H.......|....","..F.........|....","------------*----","..F.........|....","..F..S......|....","............|....","............|...."}

    Returns: 1

  8. {"......--------------.","F|FFFFFFFFFFFFFFFFFFF",".|...................",".|............S......",".|...................",".|...................",".|...................",".|...................",".|........FFFFFFFFF..",".|...................",".|...................",".|...................","-*-------------------",".|...................",".|..............F.F..",".|..............F....",".|..H...........F....",".|..............F....",".|..............F....",".|..............F....","................F....",".....................","....................."}

    Returns: 1

  9. {"............................|.............","...................F........|.............","...................F........|.............","...................F........|.............","...................F........|.............","...................F........|.............","...................F........|....|........","...............F...---------*----*----S--.","...............F............|....|.|.|....","............................|....|.|.|....","............................|....|.|.|....",".....FFFFFFFFFFFFFFFFFFFFF..|....|.|......","............................|....|.|......","............................|.H..|.|......","............................|....|.|......","............................|......|......","............................|......|......","............................|......|......","----------------------------*------*------","............................|.............","................------------*--..........."}

    Returns: 1

  10. {"|","|","|","*","|","|","|","|","|","|","|","S","|","|","|","|","H","|","|","|"}

    Returns: -1

  11. {".................|.................",".................|.................",".................|.................",".................|.................",".................|.................","................-*--------.........",".................|.................","................F|.........|.......","................F|.........|.......","................F|.........|.......","................F|H........|.......","................F|.........|.......","................F|.........|.......","........S.......F|.................","................F|.................",".................|.................",".................|................."}

    Returns: 1

  12. {"...........|......||....","...........|......||H...","...........|......||....","...........|......||....","...........|......||....","...........|......||....","...........|......||....","...........|......||....",".....F.....|......||....",".....F.....|......||....","|....F.FFFF|FFFFFF||F...","|....F.....|......||....","|....F.....|......||....","|....F.....|......||....","|....F.....|......||....","|....F.....|......||....","|..........|......||....","|..........|......||....","|..........|FFFFFF||..F.","|..........|......||....","|..........|......||....","|..........|......||....","|..........|......||....","|..........|......||....","|.FFFFFFFFF|FFFFFF||....","...........|......|.....","...........|.S....|.....","...........|......|.....","-----------*------*-----"}

    Returns: 1

  13. {"|....|", "|....|", "|....|", "|...F|" ,"|---F|" ,"|...F|" ,"|...F|" ,"|...F|" ,"|...FH" ,"|....|" ,"|....|" ,"|FS..|" ,"|....|" ,"|....|" ,"|....|" ,"|....|" ,"|....|" ,"|....|" ,"|....|" ,"|....|" ,"|....|" ,"|....|" ,"|....|" ,"|....|" ,"|....|" ,"|....|" ,"|....|" ,"|....|" ,"|....|" ,"|----|" ,"|....|" ,"|....|","|....|","|....|","*----*","|....|","|....|","|....|","|....|"}

    Returns: -1

  14. {"FFFF..............................................","..................................................","..................................................","..................................................",".....................................|............",".....................................|............",".....................................|............",".....................................|............","-------------------------------------*------------","..............................H......|............","...................F.................|............","...................F.................|............","...................F.................|............","...................F.................|............","...................F.................|............","................|..F.................|............","................|..F.................|............","................|..F.................|............","................|..F.................|............","................|.-------------------*----........","................|..F.................|............","................|..F.................|............","................|..F.................|............","...................F.................|............","...................F.................|............","...................F.................|............","...................F.................|............","...................F.................|............","...................F.................|............","...................F.................|............","...................F..............................","...................F..............................","...................F..............................","...............---------------------------------..","...................F............S................."}

    Returns: 1

  15. {"--------*-*-*----*-------*--*--------","...FFFFF|F|F|FFFFH.......|..|........",".......F..S......|..F.......|........"}

    Returns: 1

  16. {"*-SH","...F"}

    Returns: 0

  17. {"..F",".|F",".|F","H|F",".|F",".|.","...","---","...","S.."}

    Returns: 1

  18. {".....|.......|.|........|...............",".....|.......|.|........|...............",".....|.......|.|........|...............","....||.......|.|........|...............","....||.......|.|........|...............","....||....|..|.|........|...............","....||....|..|.|........|...............","....||....|..|.|........|...............","....||....|..|.|........|..|............","....||....|..|.|........|..|............","....||....|..|.|........|..|............","....||....|..|.|........|..|............","....||...F|.||.|........|..|............","....||...F|.||.|........|..|............","....||...F|.||.|........|..|..........|.","....||...F|.||.|........|..|..........|.","....||...F|.||.|........|..|..........|.","....||...F|.||.|........|..|..........|.","....||...F|.||.|........|..|..........|.","....||...F|F||F|FFFFFFFF|FF|..........|.","....||...F|.||.|........|..|..........|.","....||...F|.||.|........|..|..........|.","....||...F|.||.|........|..|..........|.","....||...F|.||.|........|.............|.","....||...F|.||.|........|.............|.","....|....F|.||.|........|.............|.",".........F|.||.|........|.............|.","..........|.||F|FFFFFFFF|.............|.","..........|.||.|........|.............|.","..........|.||.|........|.............|.","..........|.||.|........|.............|.","..........|.||.|........|.............|.","..........|.||.|........|.............|.",".....H....|.||.|........|.............|.","..........|.||.|........|...............","..........|.||.|...-----*------------...",".............|..........|...............",".............|..........|.....S.........",".............|..........|..............."}

    Returns: 2

  19. {".|...................|......|.............",".|...................|......|.............",".|...................|......|.............",".|.............|.....|......|.............",".|.............|.....|.S....|.............",".|.............|.....|......|.............",".|.............|.....|....|.|.............",".|.------------*-----*----*-*---..........",".|.............|.....|....|.|.............",".|..|..........|.....|....|.|.............",".|..|..........|.....|....|.|...........F.",".|..|..........|.....|....|.|...........F.",".|..|..........|.....|....|.|...........F.",".|..|................|....|.|...........F.",".|..|................|....|.|.............",".|..|................|....|.|.............",".|...................|....|.|.............",".|...................|....|.|.............",".|...................|....|.|.............",".|.....--------------*......|.............",".|...................|......|.............",".|...................|......|.............",".|...................|......|.............",".|............H......|......|............."}

    Returns: 1

  20. {"--------------------------...",".............................","........................H.|..","..........................|..","..FFFFFFFFFFFFFFFFFFFFFFFF|..","..........F...............|..","..........F...............|..","FFFFFFFFFFFFFFFFFFFFFFFF..|..","..........F...............|..","..........F...............|..","..........FS..............|..","..........F...............|..","..........F...............|..","..........F...............|..","..........F...............|..","..........................|..","..........................|..","..........................|..","..........................|..","..........................|..","..........................|..","..........................|..","..........................|..",".........F................|..",".........F..FFFFFFFFFFFFFF|..",".........F................|..",".........F................|..",".........F................|..",".........F................|..",".........F................|..",".........F................|..",".........F................|..",".........F................|..",".........F................|..",".........F................|..","...FFF...F................|..",".........F................|..",".........F...................",".........F...................",".........F...................",".........F...................",".........F...................",".........F...................",".........F...................",".............................",".............................",".............................","............................."}

    Returns: 0

  21. {"..............................................","...................|..........................","...................|..........................","...................|..........................","...................|..........................","...................|..........................","...................|..........................","F..................|..........................","F..................|...F......................","F..................|...F......................","F..................|...F...................|..","F..................|.FFFFFFFFFFFFFFFFFFFFFF|..","F.................||...F.........F.........|..","F..........-------**-----........F.........|..","F.................||...F.........F.........|..","F.................||...F.........F.........|..","F............|....||...F..H......F.........|..","F............|....||...F.........F.|.......|..","-------------*----**---------------*-------*..","..................||.............F.|.......|..","..................||...............|.......|..","..................||...............|.......|..","..................||...............|.......|..","...................|...............|.......|..","...................|...............|.......|..","..................S|...............|.......|..","-------------------*---------------*----------","...................|...............|..........","...................|...............|..........","...................|...............|..........","-------------------*---------------*----------","...................................|..........","...................................|..........","...................................|..........","...................................|..........","...................................|..........",".............................................."}

    Returns: 2

  22. {"....|..........|.","....|..........|.","....|..........|.","....|..........|.","....|..........|.","....|..........|.",".---*---------.|.","----*----------*-","....|..........|.","....|..........||","....|..........||","....|..........||","....|..........||","....|..........||","....|.---------*|","....|F.........||","....|.....S....||","....|..........||","....|..........||","....|..........||","F...|..........||","F...|..........||","F...|..........||","F...|..........|.","F...|..........|.","F...|..........|.","F...|..........|.","F..F|F.........|.","H...|..........|.","F...|..........|.","F...|..........|.","F...|..........|.","F...|..........|.","F...|..........|.","F...|..........|.","F...|..........|.","....|..........|.","....|..........|.","....|............","....|............","....|............","....|............","....|............"}

    Returns: 1

  23. {"..|..||.|..|.|.|..|.|..............|.......","..|..||.|..|.|.|..|.|..............|.......","..|..||.|..|.|.|..|.|..............|.......","..|..||.|..|.|.||.|.|.............||.......","..|..||.|..|.|.||.|.|.............||.......","..|..||.|..|.|.||.|.|.............||.|||...","..|..||.|..|.|.||.|.|.............||.|||S..","--*--**-*--*-*-****-*-------------**-***---","..|..||.|..|.|.||||.|.............||.|||...","..|..||.|..|.|.||||.|.............||.|||...","..|..||.|..|.|.||||.|.............||.|||...","|.|..||.|..|.|.||||.|.............||.|||...","|.|..||.|..|.|.||||.|.....|...F...||.|||...","|.|..||.|..|.|.||||.|.....|...F...||.|||...","|.|..||.|..|.|.||||||..|..|...F...||||||...","|.|..||.|..|.|.||||||..|..|...F...||||||...","|.|..||.|..|.|.||||||..|..|...F...||||||...","|.|..||.|..|.|.||||||..|..|...F...||||||...","|.|..||.|..|.|.||||||..||.|...F...||||||...","|.|..||||..|.|.||||||..||.|...F..|||||||...","|.|..||||..|.|.||||||..||.|...F..|||||||...","|.|..||||..|.|.||||||..||.|...F..|||||||...","|.|..||||..|.|.||||||..||.|...F..|||||||...","|.|..||||..|.|.||||||..||.|...F..|||||||...","|.|..||||..|.|.||||.|..||.|...F...|||||.F..","|.|..||||..|.|.||||.|..||.|...F...|||||.F..","|.|..||||..|.|.||||.|..||.|...F...|||||.F..","|.|..||||..|.|.||||.|..||.|...F...|||||.F..","|.|..||||..|.|.||||.|..||.|...F...||||..F..","|.|..||||..|.|.||||.|...|.|...F...||||..F..","|.|..||||..|.|.||||.|...|.|...F...||||..F..","|.|..||||..|.|.||||.|...|.|...F...||||..F..","|.|..||||..|.|.|.||.|...|.|...F....|||..F..","|.|..||.|..|.|...||.|...|.|...F....|||H.F..","|.|..||.|..|.|...||.|...|.|...F....|||..F..","|.|..||.|..|.|...||.|...|.|...F....|||..F..","|.|..||.|..|.|...||.|...|.|...F....|||..F..","|.|..||.|..|.|...||.|...|.|...F....|||.....","|.|..||.|..|.|...|*-*---*-*...F....|||.....","..|..||.|..|.|...||.|.........F....|.|.....","..|..||.|..|.|...||.|.........F....|.|.....","..|..||.|..|.|....|.|.........F....|.......","..|..|..|..|.|....|.|.........F....|.......","..|..|..|..|.|....|.|.........F....|......."}

    Returns: 1

  24. {"H|S"}

    Returns: 1

  25. {"|||||||||||||||||||||||||||||||||||||||||||||||||." ,"|||||||||||||||||||||||||||||||||||||||||||||||||-" ,"|||||||||||||||||||||||||||||||||||||||||||||||||-" ,"|||||||||||||||||||||||||||||||||||||||||||||||||-" ,"|||||||||||||||||||||||||||||||||||||||||||||||||-" ,"|||||||||||||||||||||||||||||||||||||||||||||||||-" ,"|||||||||||||||||||||||||||||||||||||||||||||||||-" ,"|||||||||||||||||||||||||||||||||||||||||||||||||-" ,"|||||||||||||||||||||||||||||||||||||||||||||||||-" ,"|||||||||||||||||||||||||||||||||||||||||||||||||-" ,"|||||||||||||||||||||||||||||||||||||||||||||||||-" ,"|||||||||||||||||||||||||||||||||||||||||||||||||-" ,"|||||||||||||||||||||||||||||||||||||||||||||||||-" ,"S||||||||||||||||||||||||||||||||||||||||||||||||." ,"|||||||||||||||||||||||||||||||||||||||||||||||||-" ,"|||||||||||||||||||||||||||||||||||||||||||||||||-" ,"|||||||||||||||||||||||||||||||||||||||||||||||||-" ,"|||||||||||||||||||||||||||||||||||||||||||||||||-" ,"|||||||||||||||||||||||||||||||||||||||||||||||||-" ,"|||||||||||||||||||||||||||||||||||||||||||||||||-" ,"|||||||||||||||||||||||||||||||||||||||||||||||||-" ,"|||||||||||||||||||||||||||||||||||||||||||||||||-" ,"|||||||||||||||||||||||||||||||||||||||||||||||||-" ,"|||||||||||||||||||||||||||||||||||||||||||||||||-" ,"|||||||||||||||||||||||||||||||||||||||||||||||||-" ,"|||||||||||||||||||||||||||||||||||||||||||||||||-" ,"|||||||||||||||||||||||||||||||||||||||||||||||||-" ,"|||||||||||||||||||||||||||||||||||||||||||||||||-" ,"|||||||||||||||||||||||||||||||||||||||||||||||||-" ,"|||||||||||||||||||||||||||||||||||||||||||||||||-" ,"|||||||||||||||||||||||||||||||||||||||||||||||||-" ,"|||||||||||||||||||||||||||||||||||||||||||||||||-" ,"|||||||||||||||||||||||||||||||||||||||||||||||||-" ,"|||||||||||||||||||||||||||||||||||||||||||||||||-" ,"|||||||||||||||||||||||||||||||||||||||||||||||||-" ,"|||||||||||||||||||||||||||||||||||||||||||||||||-" ,"|||||||||||||||||||||||||||||||||||||||||||||||||-" ,"|||||||||||||||||||||||||||||||||||||||||||||||||-" ,"|||||||||||||||||||||||||||||||||||||||||||||||||-" ,"|||||||||||||||||||||||||||||||||||||||||||||||||-" ,"|||||||||||||||||||||||||||||||||||||||||||||||||-" ,"|||||||||||||||||||||||||||||||||||||||||||||||||-" ,"|||||||||||||||||||||||||||||||||||||||||||||||||-" ,"|||||||||||||||||||||||||||||||||||||||||||||||||-" ,"|||||||||||||||||||||||||||||||||||||||||||||||||-" ,"|||||||||||||||||||||||||||||||||||||||||||||||||-" ,"|||||||||||||||||||||||||||||||||||||||||||||||||-" ,"|||||||||||||||||||||||||||||||||||||||||||||||||-" ,"|||||||||||||||||||||||||||||||||||||||||||||||||-" ,"|||||||||||||||||||||||||||||||||||||||||||||||||H"}

    Returns: 2

  26. {"H|.|.|.|.|.|.|.|.|.|.|.|.|.", "F|F|F|F|F|F|F|F|F|F|F|F|F|-", "S|.|.|.|.|.|.|.|.|.|.|.|.|."}

    Returns: 27

    Poor Johnny lives so close to school, but that fence makes him cross the street quite a bit just to get home.

  27. {"S|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.||.", "*************************************************-", ".||.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.", "-*************************************************", ".|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.||.", "*************************************************-", ".||.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.", "-*************************************************", ".|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.||.", "*************************************************-", ".||.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.", "-*************************************************", ".|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.||.", "*************************************************-", ".||.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.", "-*************************************************", ".|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.||.", "*************************************************-", ".||.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.", "-*************************************************", ".|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.||.", "*************************************************-", ".||.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.", "-*************************************************", ".|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.||.", "*************************************************-", ".||.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.", "-*************************************************", ".|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.||.", "*************************************************-", ".||.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.", "-*************************************************", ".|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.||.", "*************************************************-", ".||.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.", "-*************************************************", ".|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.||.", "*************************************************-", ".||.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.", "-*************************************************", ".|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.||.", "*************************************************-", ".||.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.", "-*************************************************", ".|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.||.", "*************************************************-", ".||.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.", "-*************************************************", ".|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.||.", ".|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.||H"}

    Returns: 624

  28. { ".....||..........|||........|.....|........|......", ".....||..........|||........|.....|........|......", "...S.||..........|||........|.....|........|......", ".....||..........|||........|.....|........|......", ".....||..........|||........|.....|........|......", "-----**----------***--------*-----*--------*------", "-----**----------***--------*-----*--------*------", ".....||..........|||........|.....|........|......", ".....||..........|||........|.....|........|......", ".....||..........|||........|.....|........|......", ".....||..........|||........|.....|........|......", ".....||..........|||........|.....|........|......", ".....||..........|||........|.....|........|......", ".....||..........|||........|.....|........|......", ".....||..........|||........|.....|........|......", ".....||..........|||........|.....|........|......", ".....||..........|||........|.....|........|......", "-----**----------***--------*-----*--------*------", "-----**----------***--------*-----*--------*------", "-----**----------***--------*-----*--------*------", ".....||..........|||........|.....|........|......", ".....||..........|||........|.....|........|......", ".....||..........|||........|.....|........|......", ".....||..........|||........|.....|........|......", ".....||..........|||........|.....|........|......", ".....||..........|||........|.....|........|......", ".....||..........|||........|.....|........|......", ".....||..........|||........|.....|........|......", ".....||..........|||........|.....|........|......", "-----**----------***--------*-----*--------*------", ".....||..........|||........|.....|........|......", "-----**----------***--------*-----*--------*------", ".....||..........|||........|.....|........|......", ".....||..........|||........|.....|........|......", ".....||..........|||........|.....|........|......", ".....||..........|||........|.....|........|......", ".....||..........|||........|.....|........|......", ".....||..........|||........|.....|........|......", ".....||..........|||........|.....|........|......", "-----**----------***--------*-----*--------*------", ".....||..........|||........|.....|........|......", ".....||..........|||........|.H...|........|......", ".....||..........|||........|.....|........|......", "-----**----------***--------*-----*--------*------", ".....||..........|||........|.....|........|......", ".....||..........|||........|.....|........|......", ".....||..........|||........|.....|........|......", ".....||..........|||........|.....|........|......", ".....||..........|||........|.....|........|......", ".....||..........|||........|.....|........|......"}

    Returns: 8

  29. { ".....||..........|||........|.....|.......F|......", ".....||..........|||........|.....|.......F|......", ".....||..........|||........|.....|FFFFFF..|...S..", ".....||..........|||........|.....|.......F|......", ".....||..........|||........|.....|........|F.F.F.", "-----**----------***--------*-----*--------*------", ".....||..........|||........|.....|........|.F.F.F", ".....||..........|||........|.....|........|......", ".....||..........|||........|.....|........|......", ".....||..........|||........|.....|........|......", ".....||..........|||........|.....|........|......", ".....||..........|||........|.....*--------*......", ".....||..........|||........|.....*--------*......", ".....||..........|||........|.....|..F.F..........", ".....||..........|||........|.....|.F.H.F.........", ".....||..........|||........|.....|F..............", ".....||..........|||........|.....................", "-----**----------***--------*-----*--------*------", ".....||..........|||........|.....|........|......", ".....||..........|||........|.....|........|......", ".....||..........|||........|.....|........|......", ".....||..........|||........|.....|........|......", ".....||..........|||........|.....|........|......", ".....||..........|||........|.....|........|......", ".....||..........|||........|.....|........|......", ".....||..........|||........|.....|........|......", ".....||..........|||........|.....|........|......", ".....||..........|||........|.....|........|......", ".....||..........|||........|.....|........|......", ".....||..........|||........|.....|........|......", ".....||..........|||........|.....|........|......", "-----**----------***--------*-----*--------*------", ".....||..........|||........|.....|........|......", ".....||..........|||........|.....|........|......", ".....||..........|||........|.....|........|......", ".....||..........|||........|.....|........|......", ".....||..........|||........|.....|........|......", ".....||..........|||........|.....|........|......", ".....||..........|||........|.....|........|......", "-----**----------***--------*-----*--------*------", ".....||..........|||........|.....|........|......", ".....||..........|||........|.....|........|......", ".....||..........|||........|.....|........|......", ".....||..........|||........|.....|........|......", ".....||..........|||........|.....|........|......", ".....||..........|||........|.....|........|......", ".....||..........|||........|.....|........|......", ".....||..........|||........|.....|........|......", ".....||..........|||........|.....|........|......", ".....||..........|||........|.....|........|......"}

    Returns: 3

  30. {"S-H"}

    Returns: -1

  31. { ".F-H", "S.|F" }

    Returns: -1

  32. { "S..", "--F", "-|.", ".FH" }

    Returns: -1

  33. { "S|F", "F-H" }

    Returns: -1

  34. { "|...F...F...F...F....||||........-.....|.......|||", "..F...F...F...|.|.F...||....-.-.......||..........", ".S.|||||||||||||||||||||||||||-||||||||||||||||||-", "FFFFFFFFFFFFFFFFFFFFFFFFFFFF-.-...F............F..", "||||||||||||||||||||||||||.|...FFF.............F--", "...................FFFFFFFFFFFFF...............F.|", "...............................................F.|", "...............................................F-.", "...............................................F..", "...............................................F--", "...............................................FF-", "..||||||||||||||||||||||||||||||||||||||||||||||..", "...............................................FFF", "FFFFFFFFFFFFFFF|FF-FFFFFFFFFFFFFFFFFFFFFFFFFFF--..", ".|...|............-................F..............", "..|.|.|..........|.||..F....F..F...F..............", "||||...|.........||||...F..F....F......FFFFFFFFFFF", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF--------------", "...........|||||....................---...........", ".............|.|....................-F-...........", ".............|.|....................---...........", ".............|.|....................-.-...........", "--------------F|....................|.-...........", "FFFFFFFFFFFF-FF|....................-.-...........", "...........|.|F.....................-.-...........", "FF-FFFFFFFFF-FF.....................||.||||.......", "||...|.F....|..FF.....................|....FFFFFFF", ".|||...F.........F.....FF..FF..F.F.F.F.F.F.F......", "......F...........FF-FF..FF..FF.F.F.F.F.F.F.......", "......F............F..............................", ".....F.............F..............................", ".....F.F...........FFFFFFFFFFFFFFFFFFFFFFF-FFF....", ".....FFFF.................................-.......", "........FF................................-.......", "........F.FF..............................-.......", "........FF................................-.......", "........F...F.............................-.......", "........F....F............................-.......", ".......FF.....F..........................F-.....FF", "........F......F..........................-||||||.", "........F.................................-F.H.|..", ".........FFFFFFFFFF.......................-.|||...", ".........F.|-......F......................-..F....", "...........|-.......FFFFFFFFFFFFFFFFFFFFFFFFF...F.", ".........F.|-................F....F.....||||||||.-", ".........F.--.................F...F....F..........", ".........F.-.......FF.......F.....F...F...........", ".-.....--F.||||||||..F.....F....F----F...........-", "....-----F.-..........F......-...F..F............-", ".--------F.-.......................F...........||-" }

    Returns: 20

  35. { "S.|..", "..|.H", "..|..", "....." }

    Returns: 0

  36. { "S||-H" }

    Returns: -1

  37. { "S|||||H" }

    Returns: 1

  38. { "S||", "||H" }

    Returns: -1

  39. { "S|H", "..." }

    Returns: 0

  40. { "S.................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", ".................................................H" }

    Returns: 0

  41. { "|...F...F...F...F....||||........-.....|.......|||", "..F...F...F...|.|.F...||....-.-.......||..........", ".S.|||||||||||||||||||||||||||-||||||||||||||||||-", "FFFFFFFFFFFFFFFFFFFFFFFFFFFF-.-...F............F..", "||||||||||||||||||||||||||.|...FFF.............F--", "...................FFFFFFFFFFFFF...............F.|", "...............................................F.|", "...............................................F-.", "...............................................F..", "...............................................F--", "...............................................FF-", "..||||||||||||||||||||||||||||||||||||||||||||||..", "...............................................FFF", "FFFFFFFFFFFFFFF|FF-FFFFFFFFFFFFFFFFFFFFFFFFFFF--..", ".|...|............-................F..............", "..|.|.|..........|.||..F....F..F...F..............", "||||...|.........||||...F..F....F......FFFFFFFFFFF", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF--------------", "...........|||||.......FF......|....---...........", ".............|.|...............|....-F-...........", ".............|.|.......FFFFFFF--FFF.---...........", ".............|.|.......F.....F..F...-.-...........", "--------------F|.......F.....F--F.FF|.-...........", "FFFFFFFFFFFF-FF|.......F.....F..F...-.-...........", "...........|.|F........F.....F--FFF.-.-...........", "FF-FFFFFFFFF-FF........F.....F......||.||||.......", "||...|.F....|..FF......F..............|....FFFFFFF", ".|||...F.........F.....FF..FF..F.F.F.F.F.F.F......", "......F...........FF-FF..FF..FF.F.F.F.F.F.F.......", "......F............F..............................", ".....F.............F..............................", ".....F.F...........FFFFFFFFFFFFFFFFFFFFFFF-FFF....", ".....FFFF.................................-.......", "........FF................................-.......", "........F.FF..............................-.......", "........FF................................-.......", "........F...F.............................-.......", "........F....F............................-.......", ".......FF.....F..........................F-.....FF", ".FFFFFF.F......F..........................-||||||.", ".||...F.F.................................-F.H.|..", "-.....F..FFFFFFFFFF.......................-.|||...", "......F..F.|-......F......................-..F....", "......F....|-.......FFFFFFFFFFFFFFFFFFFFFFFFF...F.", "......F..F.|-................F....F.....||||||||.-", ".........F.--.................F...F....F..........", ".........F.-.......FF.......F.....F...F...........", ".-.....--F.||||||||..F.....F....F----F...........-", "....-----F.-..........F......-...F..F............-", ".--------F.-.......................F...........||-" }

    Returns: 22


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: