Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Validate Nested Vehicle State JSON

MediumPython00:00
I
Practice interviewer
Your interviewer
In session
I
Interviewer

Welcome to the Python screen.

The question is on your right: Validate Nested Vehicle State JSON. Read through the requirements first.

Run and submit your code as often as you need. You also have five interviewer messages this session - want to talk through your approach, or are you ready to start coding?

You need to log in / sign up to run or submit.

Problem

Given a JSON-like Python object payload and a schema object schema, implement a function that validates whether the payload matches the schema. The validator must support nested objects, arrays, required fields, primitive types (string, number, boolean), allowed enum values, and numeric min/max bounds. Return a list of validation errors, where each error includes the full field path and the reason. If the payload is valid, return an empty list.

Constraints

  • 1 <= total number of schema nodes <= 10^4
  • Payload depth and schema depth are each at most 100
  • Array lengths across the payload sum to at most 10^4
  • Schema types are limited to object, array, string, number, and boolean
  • Return errors in deterministic traversal order

Function Signature

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