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
Validate Input Against Policies
00:00
5 left

Validate Input Against Policies

MediumPython

Problem

Intercom Inbox receives user-submitted text that must satisfy configurable security policies before processing. Implement a validator that checks an ASCII string against an ordered list of policies and returns the names of every policy it violates.

Formal Specification

Implement validate_input(text, policies), where text is a string and policies is a list of dictionaries. Each dictionary contains a unique name, a type, and, when required, a value:

  1. min_length: value is the minimum number of characters.
  2. max_length: value is the maximum number of characters.
  3. must_include: value is one of lowercase, uppercase, digit, or special.
  4. forbid_substring: value is a case-insensitive substring that must not occur.
  5. max_consecutive: value is the maximum number of identical consecutive characters.

Return a list of policy names violated by text, preserving the order of policies. Return an empty list when all policies pass.

Constraints

  • 1 <= len(text) <= 100000
  • 1 <= len(policies) <= 1000
  • The input contains printable ASCII characters
  • Policy names are unique
  • Every policy has a valid type and value

Function Signature

def validate_input(text, policies):
Interviewer

Your question is Validate Input Against Policies. 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.