• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests
February 19, 2024 |170 Views
PROBLEM OF THE DAY : 16/02/2024 | Flatten BST to sorted list
Description
Discussion

Welcome to the daily solving of our PROBLEM OF THE DAY with Yash Dwivedi. We will discuss the entire problem step-by-step and work towards developing an optimized solution. This will not only help you brush up on your concepts of Graph but also build up problem-solving skills.

In this problem, we are given a Binary Search Tree (BST) with n nodes, each node has a distinct value assigned to it. The goal is to flatten the tree such that, the left child of each element points to nothing (NULL), and the right child points to the next element in the sorted list of elements of the BST (look at the examples for clarity). You must accomplish this without using any extra storage, except for recursive calls, which are allowed.

Note: If your BST does have a left child, then the system will print a -1 and will skip it, resulting in an incorrect solution.

Give the problem a try before going through the video. All the best!!!
Problem Link: https://www.geeksforgeeks.org/problems/flatten-bst-to-sorted-list--111950/1
Solution IDE Link: https://ide.geeksforgeeks.org/online-cpp14-compiler/ec1d889c-ad00-455f-9903-63822df03174