Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started