Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Create Object With Getters Setters
00:00
5 left

Create Object With Getters Setters

EasyPython

Problem

Implement a CgiServiceConfig object for configuring a CGI Nederland service. The object must keep its attributes private, expose setters and getters, validate every assigned value, and apply a sequence of updates in order.

Write build_service_config(initial, updates). It must create a configuration object from the initial values, apply each update through the appropriate setter, and return a dictionary containing the final values obtained through getters.

Formal specification

  • initial is a dictionary with keys service_name, timeout, retries, and endpoints.
  • service_name is a non-empty string.
  • timeout is a positive integer measured in seconds.
  • retries is an integer from 0 through 5.
  • endpoints is a list of unique, non-empty strings.
  • updates is a list of two-item lists, where each item contains a field name and replacement value. Updates are applied sequentially, so later updates replace earlier ones.
  • Valid field names are service_name, timeout, retries, and endpoints.
  • The function returns a dictionary with the same four keys in that order.
  • Invalid values or unknown field names must raise ValueError.

Examples

Example 1

initial = {"service_name": "payments", "timeout": 30, "retries": 2, "endpoints": ["api.cgi.nl"]}
updates = [["timeout", 60], ["retries", 4]]
Output: {"service_name": "payments", "timeout": 60, "retries": 4, "endpoints": ["api.cgi.nl"]}

The updates are validated and applied in their listed order.

Example 2

initial = {"service_name": "portal", "timeout": 10, "retries": 0, "endpoints": ["web.cgi.nl", "mobile.cgi.nl"]}
updates = [["endpoints", ["web.cgi.nl"]]]
Output: {"service_name": "portal", "timeout": 10, "retries": 0, "endpoints": ["web.cgi.nl"]}

The endpoint list is replaced through its setter.

Constraints

  • 1 <= len(service_name) <= 100
  • 1 <= timeout <= 3600
  • 0 <= retries <= 5
  • 1 <= len(endpoints) <= 100
  • 0 <= len(updates) <= 10^4

Constraints

  • 1 <= len(service_name) <= 100
  • 1 <= timeout <= 3600
  • 0 <= retries <= 5
  • 1 <= len(endpoints) <= 100
  • 0 <= len(updates) <= 10^4
  • Endpoint strings are unique in every valid configuration

Function Signature

def build_service_config(initial, updates):
Interviewer

Your question is Create Object With Getters Setters. 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
Sign up free to run your codeLog inLn 2
Run your code to see test output here.