Hello Programmers/Coders, Today we are going to share solutions of Programming problems of 30 Days Of Code, HackerRank. At Each Problem with Successful submission with all Test Cases Passed, you will get an score or marks. And after solving maximum problems, you will be getting stars. This will highlight your profile to the recruiters.
In this post, you will find the solution for Day 22: Binary Search Trees in Java-HackerRank Problem. We are providing the correct and tested solutions of coding problems present on HackerRank. If you are not able to solve any problem, then you can take help from our Blog/website.
Use โCtrl+Fโ To Find Any Questions Answer. & For Mobile User, You Just Need To Click On Three dots In Your Browser & You Will Get A โFindโ Option There. Use These Option to Get Any Random Questions Answer.
Link for the Problem – Day 22: Binary Search Trees โ Hacker Rank Solution
Day 22: Binary Search Trees โ Hacker Rank Solution
Problem:
Objective
Today, we’re working with Binary Search Trees (BSTs). Check out the Tutorial tab for learning materials and an instructional video!
Task
The height of a binary search tree is the number of edges between the tree’s root and its furthest leaf. You are given a pointer, , pointing to the root of a binary search tree. Complete the getHeight function provided in your editor so that it returns the height of the binary search tree.
Input Format
The locked stub code in your editor reads the following inputs and assembles them into a binary search tree:
The first line contains an integer, , denoting the number of nodes in the tree.
Each of the subsequent lines contains an integer, , denoting the value of an element that must be added to the BST.
Output Format
The locked stub code in your editor will print the integer returned by your getHeight function denoting the height of the BST.
Sample Input
7 3 5 2 1 4 6 7
Sample Output
3
Explanation
The input forms the following BST:

The longest root-to-leaf path is shown below:

There are nodes in this path that are connected by edges, meaning our BST’s . Thus, we print as our answer.
Day 22: Binary Search Trees โ Hacker Rank Solution
import java.util.Scanner; /** * @author Techno-RJ * */ public class Day22BinarySearchTrees { static class Node { Node left, right; int data; Node(int data) { this.data = data; left = right = null; } } public static int getHeight(Node root) { return (root == null) ? -1 : Math.max(getHeight(root.left) + 1, getHeight(root.right) + 1); } public static Node insert(Node root, int data) { if (root == null) { return new Node(data); } else { Node cur; if (data <= root.data) { cur = insert(root.left, data); root.left = cur; } else { cur = insert(root.right, data); root.right = cur; } return root; } } public static void main(String args[]) { Scanner sc = new Scanner(System.in); int T = sc.nextInt(); Node root = null; while (T-- > 0) { int data = sc.nextInt(); root = insert(root, data); } sc.close(); int height = getHeight(root); System.out.println(height); } }
Hello! I know this is kinda off topic however , I’d figured
I’d ask. Would you be interested in trading links or maybe
guest authoring a blog post or vice-versa? My website addresses a
lot of the same subjects as yours and I believe we could
greatly benefit from each other. If you are
interested feel free to send me an e-mail. I look
forward to hearing from you! Great blog by the way!
tadalafil 10mg uk buy tadalafil tablets online ed pills
buy cefadroxil 500mg pills order propecia generic purchase finasteride without prescription
buy generic estrace buy cheap generic estrace prazosin us
fluconazole 100mg usa cipro 500mg drug order cipro 1000mg sale
oral vermox tretinoin gel over the counter tadalafil cost
cheap avanafil 100mg order diclofenac 100mg sale generic voltaren
cleocin 150mg uk erection pills viagra online natural ed pills
order indomethacin 50mg pills buy cefixime medication buy cefixime sale
brand trimox purchase anastrozole online buy biaxin pills
buy generic nolvadex for sale where can i buy tamoxifen buy ceftin 250mg for sale
generic bimatoprost buy generic methocarbamol online brand desyrel 50mg
minocin 100mg uk minocycline capsules purchase actos without prescription
generic sildenafil 50mg buy sildalis without prescription sildenafil 100mg pills for men
buy arava without a prescription order viagra 100mg for sale brand sulfasalazine 500 mg
order tadalafil 40mg online cialis 5mg drug cheap cialis without prescription
buy azithromycin generic neurontin 600mg drug order neurontin generic
ivermectin 50ml where can i buy ed pills prednisone 5mg price
cheap vardenafil 20mg buy zanaflex for sale order hydroxychloroquine 200mg
altace tablet purchase arcoxia online cheap etoricoxib 60mg drug
brand vardenafil 10mg buy cheap generic zanaflex order hydroxychloroquine 400mg for sale
mesalamine price order astelin for sale irbesartan cheap
coreg 25mg cheap order carvedilol 25mg pill chloroquine over the counter
acetazolamide for sale imdur uk buy imuran 50mg pills
order lanoxin online cheap order digoxin 250 mg pill molnupiravir 200 mg sale
naproxen 250mg cost buy naprosyn 500mg without prescription buy lansoprazole online
buy olumiant pills for sale order glucophage 500mg pills order lipitor pill
proventil 100 mcg canada order proventil for sale order phenazopyridine 200mg without prescription
order singulair 5mg generic singulair 10mg pill where can i buy avlosulfon
buy generic norvasc for sale order amlodipine generic buy omeprazole 20mg generic
buy adalat paypal buy allegra 120mg pill allegra 180mg cost