Grokking the Coding Interview: Patterns for Coding Questions
Ask Author
Back to course home

0% completed

Vote For New Content
Can you explain the process of input for -1 for both prevX and prevY? x = -1 an...

Alfonso Vieyra

Sep 9, 2022

Can you explain the process of input for -1 for both prevX and prevY? x = -1 and y = -1?

0

0

Comments
Comments
Design Gurus
Design Gurus3 years ago

We should avoid visiting the previous cell. Because going back to the cell from where we came, will result in a cycle, which is not correct.

At start, we set prevX and prevY to -1, as there is no previous cell. This will make the following checks true:

x + 1 != prevX ...

On this page