Statistics

Problem Statement for "ValetParking"

Problem Statement

Valet parking is used to maximize the number of cars that we can park in our lot. The parking spaces are arranged in a 100 x 100 grid of squares. Each square can hold one car, and it is possible to drive a car onto any of the four orthogonally adjacent squares (provided that it is not already occupied by a car). A car may enter or leave the lot only on the corner square whose coordinates are (0,0).

The lot is full when all but one of the squares is occupied. Given the location of the one empty square and the location of the customer's car, we want to know how many times the valet will have to get into a car and drive it before he can maneuver the customer's car to the location (0,0). The valet is not allowed to drive any of the cars out of the lot.

Create a class ValetParking that contains a method minMoves that is given the coordinates (emptyRow and emptyCol) of the one empty square in the full lot, and the coordinates of the customer's car (cusRow and cusCol). The method returns the number of times the valet will have to move a car.

Definition

Class:
ValetParking
Method:
minMoves
Parameters:
int, int, int, int
Returns:
int
Method signature:
int minMoves(int emptyRow, int emptyCol, int cusRow, int cusCol)
(be sure your method is public)

Constraints

  • emptyRow, emptyCol, cusRow, and cusCol will be between 0 and 99, inclusive.
  • (emptyRow,emptyCol) is not the same position as (cusRow,cusCol).

Examples

  1. 50

    22

    0

    0

    Returns: 0

    The customer's car is already at the exit position.

  2. 0

    0

    1

    0

    Returns: 1

    The valet can immediately drive the customer's car to the empty exit position.

  3. 0

    0

    1

    1

    Returns: 5

    One way to do this is: a) drive a car from 1,0 to 0,0 b) drive the customer's car from 1,1 to 1,0 c) drive a car from 0,1 to 1,1 d) drive a car from 0,0 to 0,1 e) drive the customer's car from 1,0 to 0,0

  4. 0

    9

    13

    0

    Returns: 82

  5. 99

    98

    99

    96

    Returns: 590

  6. 0

    2

    0

    1

    Returns: 5

  7. 50

    0

    40

    0

    Returns: 209

  8. 11

    0

    99

    0

    Returns: 578

  9. 0

    0

    99

    99

    Returns: 789

  10. 99

    99

    3

    3

    Returns: 209

  11. 5

    2

    6

    6

    Returns: 38

  12. 66

    66

    70

    1

    Returns: 415

  13. 40

    7

    80

    15

    Returns: 458

  14. 80

    15

    40

    7

    Returns: 252

  15. 0

    50

    0

    40

    Returns: 209

  16. 0

    11

    0

    99

    Returns: 578

  17. 2

    5

    6

    6

    Returns: 38

  18. 66

    66

    1

    70

    Returns: 415

  19. 7

    40

    15

    80

    Returns: 458

  20. 15

    80

    7

    40

    Returns: 252

  21. 0

    99

    98

    0

    Returns: 682

  22. 5

    62

    27

    87

    Returns: 504

  23. 28

    32

    39

    44

    Returns: 277

  24. 76

    29

    6

    85

    Returns: 552

  25. 49

    42

    58

    74

    Returns: 464

  26. 51

    34

    41

    91

    Returns: 558

  27. 13

    63

    63

    22

    Returns: 423

  28. 65

    84

    57

    82

    Returns: 474

  29. 12

    95

    67

    57

    Returns: 480

  30. 39

    53

    27

    73

    Returns: 419

  31. 98

    66

    43

    22

    Returns: 333

  32. 68

    49

    85

    11

    Returns: 486

  33. 55

    51

    36

    52

    Returns: 311

  34. 74

    75

    82

    70

    Returns: 488

  35. 80

    2

    97

    9

    Returns: 513

  36. 79

    15

    22

    42

    Returns: 311

  37. 9

    6

    6

    6

    Returns: 38

  38. 9

    5

    6

    6

    Returns: 37

  39. 5

    9

    6

    6

    Returns: 37

  40. 99

    99

    99

    98

    Returns: 591

  41. 99

    99

    98

    99

    Returns: 591

  42. 99

    99

    98

    98

    Returns: 589

  43. 99

    99

    96

    90

    Returns: 579

  44. 99

    99

    99

    0

    Returns: 591

  45. 98

    98

    99

    99

    Returns: 593

  46. 98

    99

    99

    99

    Returns: 592

  47. 0

    0

    99

    99

    Returns: 789

  48. 80

    15

    40

    7

    Returns: 252

  49. 99

    96

    98

    96

    Returns: 586

  50. 2

    0

    1

    0

    Returns: 5

  51. 10

    0

    5

    0

    Returns: 29

  52. 50

    50

    99

    50

    Returns: 589

  53. 5

    0

    3

    0

    Returns: 16

  54. 0

    2

    0

    1

    Returns: 5

  55. 10

    0

    9

    0

    Returns: 45

  56. 87

    33

    66

    92

    Returns: 601

  57. 20

    99

    87

    99

    Returns: 646

  58. 0

    30

    0

    99

    Returns: 559

  59. 50

    99

    20

    99

    Returns: 542

  60. 0

    0

    0

    99

    Returns: 589

  61. 2

    0

    2

    1

    Returns: 9

  62. 40

    7

    70

    80

    Returns: 568

  63. 15

    80

    7

    40

    Returns: 252

  64. 4

    0

    3

    0

    Returns: 15

  65. 99

    99

    1

    1

    Returns: 201

  66. 1

    90

    1

    2

    Returns: 98

  67. 7

    40

    15

    80

    Returns: 458


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: