• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests
October 15, 2023 |1.6K Views
PROBLEM OF THE DAY: 14/10/2023 | Find Common Nodes in two BSTs
Description
Discussion

Welcome to the daily solving of our PROBLEM OF THE DAY with Siddharth Hazra. 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 Binary Search Tree but will also help you build up problem-solving skills.

In this video, we are given, two Binary Search Trees. Find the nodes that are common in both of them, ie- find the intersection of the two BSTs.

Note: Return the common nodes in sorted order.

Example :

Input:
BST1:
                 5
              /     \
            1        10
          /   \      /
         0     4    7
                     \
                      9
BST2:
               10 
             /    \
            7     20
          /   \ 
         4     9
Output: 4 7 9 10

Give the problem a try before going through the video. All the best!!!

Problem Link: https://practice.geeksforgeeks.org/problems/print-common-nodes-in-bst/1
Solution IDE Link: https://ide.geeksforgeeks.org/online-cpp-compiler/d3d11e4c-d8a3-41fc-89d4-e75c57186a8c