Question: There are N rectangles numbered from 0 to N - 1 . The K - th rectangle has size A [ K ] x B
There are N rectangles numbered from to N The Kth rectangle has size AK x BK
We call two rectangles similar when:
they share a side of the same length, and
the length of the other sides differs by at most
For example:
rectangles x and x are similar,
rectangles x and x are also similar rectangles can be rotated
rectangles x and x are not similar other sides differ by
rectangles x and x are not similar either more than one side differing in length
The task is to choose as many rectangles as possible in such a way that every two chosen rectangles are similar to each other. Note that rectangles can be rotated.
Write a function:
class Solution public int solutionint A int B;
that, given two arrays A and B of N integers each, returns the maximum number of similar rectangles that can be chosen.
Examples:
A Given A and B the function should return Both rectangles can be chosen.
Given A and B the function should return The best choice is to take the rectangles in positions to After rotation, their sizes are respectively x and x
Given A and B the function should return The optimal choice is to take last two rectangles sizes x and x
Given A and B the function should return The best choice is to take the first two and the last two rectangles sizes xxx and x
Write an efficient algorithm for the following assumptions
N is an integer within the range ;
arrays A and B consist of N integers within the range
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
