Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
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 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
Build my plan
Postfix Evaluation Challenge
00:00
5 left

Postfix Evaluation Challenge

MediumPython

Problem

Given accessCodes = {XYZ, ABC, LMN, TUV...} and the postfix rule = "XYZ ABC AND XNN OR LMN NOT AND", return either true or false.

Asked in the technical phone screen stage. Implement evaluate_access_rule(accessCodes, rule).

accessCodes is a list of strings. rule is a space-separated postfix expression containing access-code names and the operators AND, OR, and NOT. A code evaluates to true when it appears in accessCodes; unknown codes evaluate to false. Return the resulting boolean. The expression is valid and contains at least one operand.

Constraints

  • 1 <= len(accessCodes) <= 10^4
  • 1 <= number of tokens in rule <= 10^4
  • Access-code names are non-empty strings without whitespace
  • The operators are exactly AND, OR, and NOT
  • The postfix expression is valid and leaves exactly one result
  • Unknown access-code names evaluate to false

Function Signature

def evaluate_access_rule(accessCodes, rule):
Interviewer

Your question is Postfix Evaluation Challenge. 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.