Can anyone explain the question of defense of kingdom

What exactly you didn’t understand?

2 Likes

So basically, you can imagine this as a chessboard with width w and height h. You have some towers placed at certain locations and each tower protects all the cells in the same row and same column as the tower. You are asked to find the area of the largest rectangle that is not protected.

Approach: On careful observation, you will realise that the answer can be simply found by taking the maximum distance between two consecutive towers along the x-direction and y-direction, and then multiplying them. So simply sort the towers according to x position and y position, and then find the maximum distance between two consecutive towers.
Link to code: CodeChef: Practical coding for everyone

1 Like

Thx bro got it