Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

LeetCode Data Structures Problem

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

Your question is LeetCode Data Structures Problem. 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

During a security audit of Atlassian Confluence permission policies, repeated policy subtrees may indicate redundant configuration or an unintended copied rule structure. Given a binary policy tree, return the root values of every subtree structure that appears at least twice.

Two subtrees are duplicates when they have the same structure and the same integer value at every corresponding node. Return each duplicate subtree root exactly once, in the order its second occurrence is discovered by postorder traversal. If no duplicate exists, return an empty list.

Formal Specification

Implement find_duplicate_subtrees(root). The input root is either None or a nested list in the form [value, left, right], where left and right use the same representation. Return a list of integer root values.

Constraints

  • 0 <= number of nodes <= 10^4
  • -10^9 <= value <= 10^9
  • Each child is either null or a valid nested tree representation

Function Signature

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