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
Coding: Optimal Configuration Under Constraints
00:00
5 left

Coding: Optimal Configuration Under Constraints

MediumPython

Problem

Write a function to determine if a given system configuration is optimal based on specified constraints.

Treat each component as independently selectable. Each component has power, memory, and benefit values. The configuration is optimal if its selected components satisfy both resource limits and produce the maximum possible total benefit.

Function signature: def is_optimal_configuration(components, selected, power_limit, memory_limit):.

components is a list of dictionaries, selected is a list of component indices, and the function returns a Boolean.

Example: components [{'power': 2, 'memory': 3, 'benefit': 5}, {'power': 3, 'memory': 2, 'benefit': 6}], selected [1], limits 3, 2 returns True. Selecting both exceeds the limits.

Constraints

  • 1 <= len(components) <= 100
  • 0 <= len(selected) <= len(components)
  • 0 <= power_limit, memory_limit <= 1000
  • 1 <= component power and memory <= 1000
  • 0 <= component benefit <= 10^6
  • Each selected index must be unique

Function Signature

def is_optimal_configuration(components, selected, power_limit, memory_limit):
Interviewer

Your question is Coding: Optimal Configuration Under Constraints. 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.