Can someone please look my solution and tell where the problem lies. I tried a lot but couldn’t figure out what is the problem with my code. Is it that I’m not giving lexicographically smallest answer?

hi,
I thought it has some issue with (-+) as I think, you just reverse the sign and just check with second row. Can you please explain why?
According to me, you have to search first non zero element (let’s say at ith index) reverse the sign of that element and then you have to check for ith column and i+1 to nth row (similar to what you have done but fixed 2nd column and 3rd row).
If anything unclear ping me back.

Happy Coding

Cheers!

Your solution goes wrong for when a[2] = 0.
You need to find the smallest value of i for which b[1][i] != 0 and use that particular row (having the index as i) instead of row indexed 2.

I was making the same mistake, anushi’s reply to her answer in this editorial solved my doubt.

Example:
input:

4 0
0 0 4 2
0 0 4 2
4 4 0 6
2 2 6 0

Your output: 0 0 -4 -2

Expected output: 0 0 -4 2