Given Binary Search Tree. The task is to find sum of all elements smaller than and equal to Kth smallest element.
The first line of input contains a single integer T denoting the number of test cases. Then T test cases follow. Each test case consists of three lines.
First line of each test case consist of integer N, denoting the number of elements in a BST.
Second line of each test case consists of N space separated integers denoting the elements in the BST. (ignore duplicate during insertion in bst)
Third line of each test case consists of an integer K, denoting the Kth smallest elements.
It should be single line output, Print the respective output in the respective line.
20 8 4 12 10 14 22
The tree for above input will look like this:
Sum of 3 smallest elements are: 4 + 8 + 10 = 22
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.