educative.io

Depth first search using iterative approach (stack)

Can you provide the iterative approach for this problem using a stack ?

Problem: Given a binary tree and a number ‘S’, find if the tree has a path from root-to-leaf such that the sum of all the node values of that path equals ‘S’.