Expected answer


5,0 is giving output 0
and 0,5 is giving output 1
can anyone explain


I think you cannot give 0 as the value of any dimension in the test cases. Giving 0 as the dimension of the grid means it does not exist which renders the question meaningless.