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
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess 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
Get started
Session Manager Class
00:00
5 left

Session Manager Class

MediumPython

Problem

Palantir Foundry may run multiple compute sessions that require exclusive worker allocations. Implement a session manager that assigns the smallest available worker IDs when a session starts and returns its allocation later.

Create a SessionManager class with these methods:

  1. start_session(session_id, units): Allocate exactly units currently free workers to session_id. Return True if successful. If the session already exists or insufficient workers are available, make no changes and return False.
  2. get_allocation(session_id): Return the worker IDs assigned to the session in ascending order. Return None if the session does not exist.

Also implement run_session_manager(capacity, operations) for evaluation. capacity is the number of workers, identified by integers from 0 through capacity - 1. Each operation is a dictionary with op equal to "start" or "get". A start operation includes session_id and units; a get operation includes session_id. Return one result per operation, using the return value of the corresponding method.

Constraints

  • 1 <= capacity <= 10^5
  • 1 <= len(operations) <= 2 * 10^5
  • 1 <= units <= capacity
  • Session IDs are nonempty strings
  • Each operation has either op = "start" or op = "get"

Function Signature

def run_session_manager(capacity, operations):
Interviewer

Your question is Session Manager Class. 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.
Code
Sign up free to run your codeLog inLn 2
Run your code to see test output here.