Associated Course(s):
Sudo Placement 2019

Consider lines of slope -1 passing between nodes (dotted lines in below diagram). The diagonal sum in a binary tree is the sum of all node’s data lying between these lines. Given a Binary Tree, print all diagonal sums.

**Note:**The **Input/****Ouput** format and **Example** given are used for system's internal purpose, and should be used by a user for **Expected Output** only. As it is a function problem, hence a user should not read any input from stdin/console. The task is to complete the function specified, and not to write the full code.

**Input:**

The first line consists of T test cases. The first line of every test case consists of N, denoting the number of edges in the tree. The second and third line of every test case consists of N, nodes of the binary tree.

**Output:**

Print space separated integers which are the diagonal sums for every diagonal present in the tree with slope -1.

**
Constraints:**

1<=T<=100

1<=N<=100

Input:

2

3

4 1 L 4 3 R 3 3 L

5

10 8 L 10 2 R 8 3 L 8 5 R 2 2 L

7 4

12 15 3

Author: shashwat jain

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

sabka_din_aayega | 317 |

maggiiiii | 248 |

thanuvinu94 | 211 |

Savage_19 | 206 |

Anugrah_kumar | 172 |

Bishnu Dev Panda | 803 |

sabka_din_aayega | 628 |

Anugrah_kumar | 562 |

okayboss | 561 |

maggiiiii | 531 |

blackshadows | 5331 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4925 |

Quandray | 4547 |

Login to report an issue on this page.