Statistics

Problem Statement for "FurnitureRobbery"

Problem Statement

Challenges on this problem will be temporarily unavailable.

Two robbers break into an antique shop and decide to steal an old famous sofa. The shop is quite messy, so this may be a difficult task.

You are given the floorplan of the shop in the String[] plan, with the first element of plan corresponding to the top row of the floorplan. Each piece of furniture is labeled with a distinct uppercase letter ('A'-'Z'). The famous sofa is labeled with 'A'. Empty cells are marked with '.'. You can push any of the pieces of furniture in any of the four directions (right, up, left and down) one cell at a time as long as it doesn't collide with any other furniture or with walls.

Your objective is to move the famous sofa so that at least one of its cells is in the top row.

Return the least number of pushes required to accomplish this goal, or -1 if it is not possible.

Definition

Class:
FurnitureRobbery
Method:
leastPushes
Parameters:
String[]
Returns:
int
Method signature:
int leastPushes(String[] plan)
(be sure your method is public)

Constraints

  • plan will contain between 2 and 5 elements, inclusive.
  • All elements in plan will have the same length.
  • Each element in plan will contain between 2 and 6 characters, inclusive.
  • Each character in plan will be an uppercase letter ('A'-'Z') or '.'.
  • Each piece of furniture will occupy at least 2 cells.
  • Cells with same letters will be connected.
  • There will be exactly one 'A' piece.

Examples

  1. {"......", ".BBB.X", ".B.B.X", "DDCC.Y", "..AAAY"}

    Returns: 13

    ...... ...... BBB... BBB... BBB... BBB... BBBAAA .BBB.X .BBB.X B.B..X B.B..X B.B..X B.B... B.B... .B.B.X 3 moves .B.B.X 2 moves .....X 2 moves ..AAAX 1 move ..AAAX 2 moves ..AAA. 3 moves ...... DDCC.Y ------> CC...Y ------> CC...Y ------> CC...Y ------> CC..Y. ------> CC..YX ------> CC..YX ..AAAY DDAAAY DDAAAY DD...Y DD..Y. DD..YX DD..YX 13 pushes total.

  2. {"......", ".BBB.X", ".B.B.X", "....YY", "..AAAY"}

    Returns: 11

  3. {"...C.C", "BBBCCC", "B.B...", ".XX..Y", "..AAAY"}

    Returns: 13

  4. {"......", "ZBBBXY", "ZBBBXY", "EAAACC", "E.DDCC"}

    Returns: 20

  5. {"......", "BBB...", "BCBC..", ".CCC.Y", "..AAAY"}

    Returns: 16

  6. {"......", "BBB.ZZ", "BCBC..", ".CCC.Y", "..AAAY"}

    Returns: 21

  7. {".C", "BC", "BC", "B.", "AA"}

    Returns: -1

  8. {".XX.Y.", ".AA.Y."}

    Returns: 3

  9. {"QQWWEE", "RRTTYY", "UUIIOO", "PPSSDD", "ZZ..AA"}

    Returns: 25

  10. {"QQWWEE", "RRTTYY", "......", "......", "ZZ..AA"}

    Returns: 12

  11. {"YYYXXX", "ZBBBB.", "ZBBBBM", "VVAA.M", "..AATT"}

    Returns: -1

  12. {"YYYXXX", "ZBBBB.", "ZBBBB.", "VVAATO", "..AATO"}

    Returns: -1

  13. {"YYSSXX", "ZBBBB.", "ZBBBB.", "VVAATO", "..AATO"}

    Returns: -1

  14. { "QQWTEE", "RRWTYY", "PUSSDO", "PUIIDO", "ZZ..AA"}

    Returns: 45

  15. { "QQWTEE", "RRWTYY", "PUSSDO", "PUIIDO", "....AA"}

    Returns: 26

  16. { "......", ".ADD..", ".AAD..", ".DAD..", ".DDD.."}

    Returns: -1

  17. { ".ZZ...", ".ZFFFF", ".FF.FA", ".F.DAA", "..DD.."}

    Returns: -1

  18. {"......", ".CCDD.", "XXBBBY", "XXBBBY", "....AA"}

    Returns: 13

  19. {"..DD..", ".BBBZZ", ".BBBYY", "SBBBXX", "SAAA.."}

    Returns: 29

  20. {"BBCCDD", "XXYYZZ", "SSRRFF", "TT..VV", ".AA.LL"}

    Returns: 21

  21. {"....",".BB.",".AA."}

    Returns: 4

  22. {"AAA","..."}

    Returns: 0

  23. {"AAAAAA","BBBBBB","CCCCCC","DDDDDD","EEEEEE"}

    Returns: 0

  24. { "BB.A.E", "BAAA.E", "BBA.EE", "CAA.EE", "CA.EEE" }

    Returns: 0

  25. { "BB...E", "BAAA.E", "BBA.EE", "CAA.EE", "CA.EEE" }

    Returns: 2

  26. {"ZZYYXX", "WWVVRR", "QQEETT", "DDFFGG", ".AAUU." }

    Returns: 27

  27. {"......", "ZBBBXY", "ZBBBXY", "EAAACC", "E.DDCC" }

    Returns: 20

  28. {"DDCCBB", "EEFFGG", "HHIIJJ", "KKMMNN", "AALL.." }

    Returns: 27

  29. {"..BCCC", "D.BFF.", "D.XX.Y", "ZZ...Y", "..AASS" }

    Returns: 10

  30. {"ZZZZZZ", "AA.BB.", "CC.DD.", "EE.FF.", "GG.HH." }

    Returns: -1

  31. {"BBCCDE", "FFGGDE", "....HH", "XX.YY.", "AAANN." }

    Returns: 27

  32. {"MMNN..", "JJKKLL", "GGHHII", "DDEEFF", "AABBCC" }

    Returns: 29

  33. {"F.G.H.", "F.G.H.", "DD.EE.", "BB.CC.", "AAAAAA" }

    Returns: -1

  34. {"BBCCDD", "EEFFGG", "HHIIJJ", "KKLLMM", "AANN.." }

    Returns: 27

  35. {"BBBBBB", "AABBCC", "DDEEFF", "GGHHII", "JJKK.." }

    Returns: -1

  36. {"..JJKK", "NNHHII", "MMFFGG", "LLDDEE", "AABBCC" }

    Returns: 25

  37. {"BBCCDD", "EEFFGG", "......", "PP....", "AAAAA." }

    Returns: -1

  38. {"BBCCDD", "EEFFGG", "HHIIJJ", "KKLLMM", "OO..AA" }

    Returns: 25

  39. {".DE..G", "BDE.FG", "BACCF.", "AAA..." }

    Returns: 13

  40. {"......", ".BBB.X", ".B.BBX", "DDCC.Y", "..AAAY" }

    Returns: -1

  41. {"..BBCC", "DDEEFF", "GGHHII", "JJKKLL", "MMNNAA" }

    Returns: 29

  42. {"ZZZZZZ", "AA..DD", "EE..GG", "CCQQYY", "MMNNWW" }

    Returns: -1

  43. {".DEFGZ", "CDEFGZ", "C.....", "B.....", "BAAAAA" }

    Returns: 31

  44. {"XXYYZZ", "FFSSEE", "DDMMGG", "RRWWNN", "..AA.." }

    Returns: 23

  45. {"BBBRRR", "CCDDEE", "FFGG..", "AAHHII", "JJ...." }

    Returns: 20

  46. {"BBCCDD", "EEFFGG", "HHIIJJ", "KKLLMM", "...AAA" }

    Returns: -1

  47. {"JJLL..", "II..FG", "EEE.FG", "DCBBBB", "DC..AA" }

    Returns: 28

  48. {"AA...", ".....", "BB..." }

    Returns: 0

  49. {"LLMM..", "IIJJKK", "FFGGHH", "ZZDDEE", "AABBCC" }

    Returns: 29

  50. {"..QQWW", "RRTTYY", "UUIIOO", "GGHHJJ", "BBCCAA" }

    Returns: 29

  51. {"......", "BBCCDD", "HHLLLL", "KKSSMM", "AAEEPP" }

    Returns: 21

  52. {"..BBBB", "..DDCC", "EEFFGG", "HHIIJJ", "KKLLAA" }

    Returns: 24

  53. {"EEFFLL", ".DD.GG", "CC.HH.", "BBJJZZ", "KKAAYY" }

    Returns: 19

  54. {"BBBBB.", "AACCDD", "EEFFGG", "HHIIJJ", "KKLL.." }

    Returns: -1


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: