Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Validate Input Against Policies

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

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

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