Answer: INSTAMOJO Online Assessment Interview Question | On-Campus(2024)

Answer · Posted Jun 2026

Approach For every rectangle, reduce its ratio using GCD. Store the reduced ratio in a HashMap. If the same ratio has appeared before, all previous rectangles with that ratio form new pairs. Add the count of previous occurrences to the answer. Update the frequency in the map. Strategy Normalize each rectangle ratio. Use a HashMap to track frequency of each ratio. Count pairs while traversing. Avoid floating-point precision issues by storing reduced ratios as strings. Java Code import java.util.HashMap; import ...

The full answer & interview discussion are available to premium members.

Log in Create a free account