Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Preloaded Problem Engine Class

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

Your question is Preloaded Problem Engine 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

Coalition Control organizes cyber-risk assessment challenges into named problem sets. Implement an engine that is preloaded with those sets, preserves problem order, removes duplicates, supports combined set queries, and tracks completed problems.

Create a ProblemSetEngine and a wrapper function run_engine(problem_sets, operations).

Formal Specification

  • problem_sets is a dictionary mapping a set name to a list of problem ID strings. Duplicate IDs within a set are possible.
  • Each operation is a dictionary with one of these forms:
    • {"op": "list", "set": name}: return unique problem IDs from that set, in first-seen order.
    • {"op": "union", "sets": [name1, name2, ...]}: return unique IDs from the named sets, scanning sets in the given order.
    • {"op": "complete", "problem": id}: mark the problem complete and return true only if it was known and not already complete. Otherwise return false.
    • {"op": "next", "set": name}: return the first incomplete problem in that set, or null if none remain.
  • Return one result for every operation, in operation order.
  • All referenced set names are valid.

Constraints

  • 1 <= number of sets <= 10^4
  • 1 <= total problem references <= 10^5
  • Each set contains at least one problem reference
  • Problem IDs and set names are non-empty strings
  • There are at most 10^5 operations

Function Signature

def run_engine(problem_sets, operations):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output