Search
⌘K

Leetcode 3486. Longest Special Path II

Given a rooted tree with edge lengths and node values, find a downward ancestor→descendant path that maximizes total edge length under the constraint that node values along the path are all distinct except that at most one value may appear twice; return the maximum length and, among all such longest paths, the minimum number of nodes. The core challenge is traversing the tree while tracking value occurrences (allowing one duplicate) to compute longest valid path length and tie-break by node count for n up to 5·10^4.


Question Timeline

See when this question was last asked and where, including any notes left by other candidates.

Comments

Your account is free and you can post anonymously if you choose.