I have an alternate method. At every level, maintain records with (x-axis value, nodeValue) and keep them in a queue.
After traversal is done, you can sort the elements based on x-Axis value and sum up the nodeValue for records having same x-axis value. But complexity is becoming O(nlogn) because of sorting. On Oct 16, 6:38 pm, sravanreddy001 <sravanreddy...@gmail.com> wrote: > Even I see this as the best solution... > O(n) time and space.. -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.