Grokking the Coding Interview: Patterns for Coding Questions
Ask Author
Back to course home

0% completed

Vote For New Content
what if all of the numbers in the nodes are negative?

Athanasios Petsas

Feb 15, 2022

what if all of the numbers in the nodes are negative?

2

0

Comments
Comments
Design Gurus
Design Gurus4 years ago

Please see the last example in the code.

A
Austin McDaniel3 years ago

I see why he would have thought it wouldn't work for something like:

root = TreeNode(-5) root.left = TreeNode(-3)

just bc the code comment states to ignore any path with an overall negative sum it can be a little confusing.

SHLOK KOTHARI
SHLOK KOTHARI2 years ago

We can still safely ignore the paths with negative sum. If the parent node is positive, the negative path sum will reduce its value. If the parent node is negative, the negative path sum will also reduce its value.

Example -

  • If the parent node is 4 and -3 is returne...

On this page