Google interview stage 2 [Hyd, IND, 2020 ,July]
Anonymous User
1105

There is a grid like field which has holes in each hole there is certain amount of carrots denoted by C
Given an M * N grid , M row , N columns. Now there is a rabbit at standing at position (i, j) in the grid . Rabbit wants to get as much as it can, but he can cross a row at most x number of times and columns at most y number of times and can move only in four directions left ,right, up and down by 1. Rabbit has to reach at position (i ' , j ' ) after taking carrots.Find the maximum number of carrots he can get.

crossing row or column means moving from one column to other or moving one row to other row .
It is guaranteed that rabbit will reach destination.

Contraints
2 < M, N < 10^3
2 <X, Y<10^6

Input :
M=4, N=4
field = [[2,3,1,4], [2,0,0,2], [1,2,5,6],[3,4,2,1]]
source = [i, j] = [3,0]
destination = [i', j'] = [1,3]
x=4 , y=3
Output : 25

Comments (5)