Skip to content
Discussion options

You must be logged in to vote

We need to find the rectangle with the longest diagonal from a given list of rectangles. If multiple rectangles have the same longest diagonal, we then select the one with the largest area. The solution involves calculating the diagonal length for each rectangle and comparing these lengths, while also considering the area in case of ties.

Approach

  1. Problem Analysis: The problem requires processing each rectangle's dimensions to determine which one has the longest diagonal. The diagonal of a rectangle can be calculated using the Pythagorean theorem: diagonal = sqrt(length2 + width2). However, to avoid floating-point inaccuracies, we compare the squares of the diagonals (i.e., length2 + width2

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@topugit
Comment options

topugit Aug 26, 2025
Collaborator

@mah-shamim
Comment options

mah-shamim Aug 26, 2025
Maintainer Author

Answer selected by topugit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested easy Difficulty
2 participants