Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Deep Equality for Nested Data

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

Your question is Deep Equality for Nested Data. 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

Patreon configuration data can contain nested objects and arrays, such as creator page settings or membership benefit definitions. Implement is_equal(a, b) to determine whether two JSON-like values are structurally and recursively equal.

Formal Specification

The inputs a and b are JSON-like Python values composed only of None, booleans, integers, floats, strings, lists, and dictionaries with string keys. Return True only when:

  1. Both values have the same type and scalar values are equal.
  2. Lists have the same length and equal elements at the same indices.
  3. Dictionaries have the same key set and equal values for every key, regardless of insertion order.

You may assume the structures are acyclic. Do not convert the values to strings or sort serialized output. Implement the comparison directly.

Constraints

  • 0 <= nesting depth <= 100
  • Each structure contains at most 10^4 total values
  • Dictionary keys are strings
  • Inputs are acyclic JSON-like values
  • Lists preserve order, while dictionary insertion order is ignored

Function Signature

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