Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Core OOP Concepts Overview
00:00
5 left

Core OOP Concepts Overview

MediumPython

Problem

What do you know about OOP?

Implement a small object-oriented design that calculates the combined area of circles and rectangles. Use a base Shape abstraction and polymorphic area() methods instead of placing all area formulas in one conditional-heavy function.

The function receives shapes, a list of dictionaries, and returns the total area rounded to two decimal places. Each dictionary is either {"type": "circle", "radius": number} or {"type": "rectangle", "width": number, "height": number}.

Constraints

  • 0 <= len(shapes) <= 10^4
  • Each shape type is either "circle" or "rectangle"
  • All dimensions are non-negative numbers
  • Return the result rounded to exactly two decimal places numerically

Function Signature

def calculate_total_area(shapes):
Interviewer

Your question is Core OOP Concepts Overview. Start with the requirements in the Question tab.

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.
CodePython 3
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.