Trace .
Row 0: try col 0. Place Q at (0,0). Mark col 0, diag 0-0=0, diag 0+0=0. Row 1: col 0 attacked. col 1 attacked (diag). Try col 2. Place Q at (1,2). Row 2: try columns... col 0 attacked diagonally. col 1 attacked. col 2 attacked (column). col 3 attacked diagonally. No valid position. Backtrack. Row 1: try col 3. Place Q at (1,3). Row 2: col 1 works. Place Q at (2,1). Row 3: col 0 attacked. col 2? Check... blocked. No valid. Backtrack. ...continue exploring.
Eventually find valid solutions.
Worst case exponential, but pruning makes it tractable. Time: roughly . Space: for recursion and tracking.