Question
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
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