Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Session Manager Class

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

Your question is Session Manager Class. 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

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):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output