Does anyone see a better way to do this problem?
Question Details
constraints are N <= 1000 and -1000 <= node value <= 1000 <a href="https://leetcode.com/problems/maximum-distinct-path-sum-in-a-binary-tree/description/>
Full Details
constraints are N <= 1000 and -1000 <= node value <= 1000 <a href="https://leetcode.com/problems/maximum-distinct-path-sum-in-a-binary-tree/description/.
Time complexity is O(n^2 * logn * n/W). Got AC in C++ but don't think I can link my submission here. 2/ Run a dfs. At each node, we consider all pairs of two children in its subtree. Each of those children tells us (sumToNode, bitsetToNode). We can aggregate these and update our result. It looks cubic in time but is actually squared. O(n^2 * n/W)
About This Question
This is a reported interview question from a square/block interview for a swe role reported in 2026.
It covers the following topics: Binary Tree, Bit Manipulation, Graph, Sql .
Difficulty rating: Easy