Doubt in the second method

In the second method when we map -3 to 3 to an array from 0 to 6, we did r-c+n-1, but isnt it wrong? because when r-c=-3 we add n-1(which means 7-1) to it which maps -3 to 3 and +3 to 6

also, if n=5, shouldnt we add n-2 instead of n-1? because -3+5-2=0 but if we add n-1 we get -3+5-1 which is equal to 1

Hi Vipul. to which question are u referring to?? can u share the link of the same

N-queens question(the second method)

can u tell at what time of video are u referring to??

around the 41 mins time mark

Hi Vipul.
so ur first doubt was this -
In the second method when we map -3 to 3 to an array from 0 to 6, we did r-c+n-1, but isnt it wrong? because when r-c=-3 we add n-1(which means 7-1) to it which maps -3 to 3 and +3 to 6
considering 5*5 array when we add n-1 (ie 5-1 = 4) -3 is mapped to 1 and 3 is mapped to 7.
but as u said if we add n-2 then -3 is mapped to 0 and 3 is mapped to 6.

Hope this clears ur doubts. there is also another way out if u don’t want to preform all this addition and all. u can maintain a hashmap as it can store negative values as well. space complexity remains the same.

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.