Given a binary tree of **N** edges, where every node contains distinct data. The task is to find the maximum path sum. The path may start and end at any node in the tree.

**Input:**

First line of input contains number of testcases T. For each testcase, there will be two lines, first of which containing the number of edges (between two nodes) in the tree. Next line contains N pairs (considering **a** and **b**) with a '**L**' (means node b on left of a) or '**R**' (means node b on right of a) after a and b.

**Output:**

Print the maximum path sum in the binary tree.

**User Task:**

The task is to **complete **the **findMaxSum **that takes **root **as input and returns max sum.

**Constraints:**

1 <= T <= 100

1 <= N <= 10^{3}

**Example:
Input:**

2

6

10 2 L 2 20 L 2 1 R 10 -25 R -25 3 L -25 4 R

3

10 2 L 10 5 R 5 -2 R

**Output:**

32

17

**Explanation:
Testcase 2:** Path in the given tree goes like 2, 10, 5, which gives the max sum as 17.

Author: Ayush Govil 1

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.

thanuvinu94 | 425 |

the_coder95 | 380 |

RishabhTanwar1 | 280 |

shubham3174 | 208 |

RitikRosan | 202 |

the_coder95 | 1226 |

RishabhTanwar1 | 1000 |

thanuvinu94 | 634 |

tathagat289 | 628 |

themanhasnoname | 620 |

blackshadows | 5331 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4885 |

Quandray | 4547 |

Login to report an issue on this page.