Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 6420 |

@blackshadows | 6376 |

@mb1973 | 5594 |

@Quandray | 5231 |

@akhayrutdinov | 5111 |

@saiujwal13083 | 4510 |

@sanjay05 | 3762 |

@kirtidee18 | 3673 |

@marius_valentin_dragoi | 3522 |

@sushant_a | 3459 |

@verma_ji | 3412 |

Complete Leaderboard | |

Handle | Score |

@codersgroup18 | 783 |

@Manikanta punnam | 605 |

@sriramgoparaju99 | 594 |

@rdakka | 538 |

@praveenbgp6 | 529 |

@prankursharma31 | 518 |

@yashkaril4 | 517 |

@purohitmn02 | 467 |

@sonamnigam1999 | 443 |

@sonamkumari63928 | 441 |

@shubhamstudent5 | 433 |

Complete Leaderboard |

Given a Binary Tree of size N, you need to find all the possible paths from root node to all the leaf node's of the binary tree.

**Example 1:**

**Input:**
1
/ \
2 3
**Output: **1 2 #1 3 #
**Explanation: **
All possible paths:
1->2
1->3

**Example 2:**

**Input:
**10
/ \
20 30
/ \
40 60**
Output: **10 20 40 #10 20 60 #10 30 #

**Your Task:**

Your task is to complete the function **Paths()** that takes the root node as an argument and return all the possible path. (All the path are printed '#' separated by the driver's code.)

**Note: **The return type

**cpp: **vector

**java: **ArrayList>

**python: **list of list

**Expected Time Complexity: **O(N).

**Expected Auxiliary Space: **O(H).

**Note: **H is the height of the tree.

**Constraints:**

1<=N<=10^{3}

**Note: **The **Input/Ouput** format and **Example** given, are used for the 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 the stdin/console. The task is to complete the function specified, and not to write the full code.

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes
Root to Leaf Paths

...