why [r-c+n-1] for left diagonal and [r+c] for right diagonal??
Advanced backtracking webinar
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.
please check at 31:19
@Ambuj-Singh-514796906079795
Each diagonal follows a certain property.
The main diagonal (from top left to bottom right) has indices such the difference between r and c for its coordinates (r,c) is constant across the diagonal.
Since we are taking the difference, it could go negative though. Hence to ensure that negative differences do not create a problem while indexing, we add a constant number i.e. n-1 to it to make it positive.
This is not needed while indexing the cells of the other elements. Hence r+c is sufficient for the other diagonal.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.