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
ExperiencesCoaching
New
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
Start free
Trie-Based Nested JSON Field Removal
00:00
5 left

Trie-Based Nested JSON Field Removal

HardPython

Problem

Palo Alto Networks frontend surfaces such as Cortex XSIAM may receive deeply nested JSON configuration and alert objects. Implement a function that removes every object field whose dot-separated path appears in a blocked-path list, including the field's entire subtree.

Formal Specification

Given a JSON-compatible value data and an array blocked_paths, return a new JSON-compatible value with all matching fields removed. A path such as user.credentials.token refers only to object keys, and array elements do not add path components. Apply the same path rules independently to every object inside an array. Preserve the order of object keys and array elements. Do not mutate data.

Use a trie for blocked paths so shared prefixes are represented once and a blocked subtree can be skipped without traversing its descendants. Object keys used in paths do not contain periods. The root itself is never blocked.

Constraints

  • data contains only objects, arrays, strings, numbers, booleans, and null
  • 1 <= number of blocked paths <= 10^4
  • Each path contains 1 to 100 keys
  • The total number of path components is at most 10^5
  • The JSON tree contains at most 10^5 values
  • Object keys used in paths do not contain periods
  • The root itself is never blocked

Function Signature

def filter_json(data, blocked_paths):
Interviewer

Whenever you're ready, walk me through your approach or go straight to the code. The requirements are in the Question tab.

Sign up free to run or submit. Log in
CodePython 3
Sign up free to run your code. Your draft is saved.Run with a free accountLog inLn 2
Run your code to see test output here.