⌘K
Flycodx

PhonePe Transaction Tree Diameter

PhonePe Transaction Tree Diameter

MediumTrees100% accepted

PhonePe models a UPI transaction dependency graph as a binary tree. The settlement latency is determined by the diameter of the tree — the longest path between any two nodes. Given the root of a binary tree, return the length of the diameter (number of edges on the longest path between any two nodes).

Approach

Find the diameter (longest path between any two nodes) of a binary tree.

Input

5 1 2 3 4 5

Output

3
solution.py
Loading editor...
Test 1
Test 2
Test 3

Press Run to test your custom input, or Submit to judge against all test cases.

Sign in to continue

Create a free account to run code, submit solutions and track progress.

  • Free forever — no credit card
  • 10+ languages with live execution
  • Points, streaks & leaderboards
Auto Save OnLn 1, Col 1Spaces: 4UTF-8LFPython 3