Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Given a set of n rectangles. Ith rectangle has length[i] length and breadth[i] breadth. One rectangle can overlap another rectangle, if the former has both

Given a set of n rectangles. Ith rectangle has length[i] length and breadth[i] breadth. One rectangle can overlap another rectangle, if the former has both >= length as well as >= breadth than the latter. We dont consider rotations of rectangles while considering overlapping. E.g. a 3 x 5 rectangle can overlap 2 x 4 rectangle, but not a 4 x 2 rectangle. A 3 x 5 rectangle also overlaps rectangles of sizes 3 x 4, 2 x 5, as well as 3 x 5 (another rectangle with same dimensions) We want to partition these rectangles into different groups, such that within each group, no rectangle can overlap another one. What is the minimum number of groups that we can partition the rectangles into? Constraints: 1 <= n <= 5000 1 <= length[i], breadth[i] <= 10^5 Examples: n = 5 length = [1, 2, 5, 4, 3] breadth = [3, 5, 2, 1, 4] Answer = 2 We can partition these rectangles into 2 groups, group 1 containing rectangles 1 and 4 (1 x 3, 4 x 1), and group 2 containing rectangles 2, 3 and 5 (2 x 5, 5 x 2, 3 x 4). [execution time limit] 4 seconds (py3) [input] array.integer length [input] array.integer breadth [output] integer. The question should run in O(nlogn), rather than O(n2)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Introduction To Databases And Data Warehouses

Authors: Nenad Jukic, Susan Vrbsky, Svetlozar Nestorov

1st Edition

1943153191, 978-1943153190

More Books

Students also viewed these Databases questions

Question

How was their resistance overcome?

Answered: 1 week ago

Question

What is Ramayana, who is its creator, why was Ramayana written?

Answered: 1 week ago

Question

To solve by the graphical methods 2x +3y = 9 9x - 8y = 10

Answered: 1 week ago

Question

What is Change Control and how does it operate?

Answered: 1 week ago

Question

How do Data Requirements relate to Functional Requirements?

Answered: 1 week ago