Problem Statement
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
50
22
0
0
Returns: 0
The customer's car is already at the exit position.
0
0
1
0
Returns: 1
The valet can immediately drive the customer's car to the empty exit position.
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
0
9
13
0
Returns: 82
99
98
99
96
Returns: 590
0
2
0
1
Returns: 5
50
0
40
0
Returns: 209
11
0
99
0
Returns: 578
0
0
99
99
Returns: 789
99
99
3
3
Returns: 209
5
2
6
6
Returns: 38
66
66
70
1
Returns: 415
40
7
80
15
Returns: 458
80
15
40
7
Returns: 252
0
50
0
40
Returns: 209
0
11
0
99
Returns: 578
2
5
6
6
Returns: 38
66
66
1
70
Returns: 415
7
40
15
80
Returns: 458
15
80
7
40
Returns: 252
0
99
98
0
Returns: 682
5
62
27
87
Returns: 504
28
32
39
44
Returns: 277
76
29
6
85
Returns: 552
49
42
58
74
Returns: 464
51
34
41
91
Returns: 558
13
63
63
22
Returns: 423
65
84
57
82
Returns: 474
12
95
67
57
Returns: 480
39
53
27
73
Returns: 419
98
66
43
22
Returns: 333
68
49
85
11
Returns: 486
55
51
36
52
Returns: 311
74
75
82
70
Returns: 488
80
2
97
9
Returns: 513
79
15
22
42
Returns: 311
9
6
6
6
Returns: 38
9
5
6
6
Returns: 37
5
9
6
6
Returns: 37
99
99
99
98
Returns: 591
99
99
98
99
Returns: 591
99
99
98
98
Returns: 589
99
99
96
90
Returns: 579
99
99
99
0
Returns: 591
98
98
99
99
Returns: 593
98
99
99
99
Returns: 592
0
0
99
99
Returns: 789
80
15
40
7
Returns: 252
99
96
98
96
Returns: 586
2
0
1
0
Returns: 5
10
0
5
0
Returns: 29
50
50
99
50
Returns: 589
5
0
3
0
Returns: 16
0
2
0
1
Returns: 5
10
0
9
0
Returns: 45
87
33
66
92
Returns: 601
20
99
87
99
Returns: 646
0
30
0
99
Returns: 559
50
99
20
99
Returns: 542
0
0
0
99
Returns: 589
2
0
2
1
Returns: 9
40
7
70
80
Returns: 568
15
80
7
40
Returns: 252
4
0
3
0
Returns: 15
99
99
1
1
Returns: 201
1
90
1
2
Returns: 98
7
40
15
80
Returns: 458