Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Rectangular Containment Check

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Rectangular Containment Check. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Implement CGRectContainsRect(rect1, rect2): return true if rect1 fully contains rect2, otherwise false.

Asked in the technical phone screen stage. First of two questions in an iOS phone screen.

Represent each rectangle as [x, y, width, height], where (x, y) is its lower-left corner. Return True when every point of rect2 lies inside or on the boundary of rect1; otherwise return False.

Constraints

  • Each rectangle is represented as [x, y, width, height].
  • 1 <= width, height <= 10^9
  • -10^9 <= x, y <= 10^9
  • All values are integers or floating-point numbers.

Function Signature

def CGRectContainsRect(rect1, rect2):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output