2
public int minCost(int[] startPos, int[] homePos, int[] rowCosts, int[] colCosts) {5
// if home is to the down of start move, down till there6
if (homePos[0] > startPos[0]) {7
int i = startPos[0] + 1;8
while (i <= homePos[0]) {9
total += rowCosts[i]; // adding cost while moving corresponding to the cell14
// else if home is up from the start, move up till there15
else if (homePos[0] < startPos[0]) {16
int i = startPos[0] - 1;17
while (i >= homePos[0]) {18
total += rowCosts[i]; // adding cost while moving corresponding to the cell23
// if home is right to the start, move right till there24
if (homePos[1] > startPos[1]) {25
int i = startPos[1] + 1;26
while (i <= homePos[1]) {27
total += colCosts[i]; // adding cost while moving corresponding to the cell32
// else if home is left to the start, move left till there33
else if (homePos[1] < startPos[1]) {34
int i = startPos[1] - 1;35
while (i >= homePos[1]) {36
total += colCosts[i]; // adding cost while moving corresponding to the cell