Nqueen Optimization Doubt


why i am not getting answer

Hey @dare_devil_007, this problem doesn’t work with n<=4 as there’s no such configuration possible where you can place 4 or less the 4 queens in table and they don’t intersect each other’s path. Try it for n=5 as I have tested , it’s working fine :grinning:
Happy to help

1 Like

ok thanks got it and can you please explain the time complexity of the above code as i am not able to figure it out

It’s O(n^3) because you are checking for every ith position n^2 time.
Hope this will help you :grinning:

in worst case in every row we are iterating through all cloumns and each row we r checking for every column in next row which is n^n and as we r doing for all the rows it has to be n*n^n right?

Absolutely right :grinning:

what i said is for generation of all possible configurations na??? but if it generating only one configuration it would be n^n complexity right?

Yes, only for generating one configuration

1 Like