I am Rishabh this side!
π¨βπ» Code Lover Β Β π OSS @webpack Β Β π¨π½βπ» Product Engineer at Sprinklr Β Β β€ JS, C++, Python
icons from https://simpleicons.org/
Code to basic binary tree problems follow along ππ
License: MIT License
I am Rishabh this side!
π¨βπ» Code Lover Β Β π OSS @webpack Β Β π¨π½βπ» Product Engineer at Sprinklr Β Β β€ JS, C++, Python
icons from https://simpleicons.org/
Given a binary tree, find it's diameter which is the largest distance possible between any two nodes
Input Format
A binary tree in level order format
Output
diameter
Given a binary tree, print the preorder traversal of given tree.
Pre-order traversal: Root -> Left -> Right
Input Format
Elements in level order form (separated by space)
(If any node does not have left or right child, take -1 in its place)
Output Format
Pre-order traversal, elements separated by space
Given a binary tree, find and return the sum of all nodes.
Input format
Elements in level order form (separated by space).
If any node does not have left or right child, take -1 in its place.
Given Preorder and Inorder traversal of a binary tree, create the binary tree associated with the traversals.You just need to construct the tree and return the root.
Note: Assume binary tree contains only unique elements.
Input format
Line 1 : n (Total number of nodes in binary tree)
Line 2 : Pre order traversal
Line 3 : Inorder Traversal
Output Format
Elements are printed level wise, each level in new line (separated by space).
Given a binary tree, print the zig zag order i.e print level 1 from left to right, level 2 from right to left and so on. This means odd levels should get printed from left to right and even level right to left.
Input format
Elements in level order form (separated by space)
(If any node does not have left or right child, take -1 in its place)
Output Format
Elements are printed level wise, each level in new line (separated by space).
Given a binary tree, find and return the height of given tree.
Input format
Nodes in the level order form (separated by space).
If any node does not have left or right child, take -1 in its place
Output format
Height
Constraints
1 <= N <= 10^5
Given a Binary Tree and an integer x, check if node with data x is present in the input binary tree or not. Return true or false.
Input format
Line 1 : Elements in level order form (separated by space)
(If any node does not have left or right child, take -1 in its place)
Line 2 : Integer x
Output format
True or False
Given a binary tree, write code to create a separate linked list for each level. You need to return the array which contains head of each level linked list.
Input format
Elements in level order form (separated by space).
If any node does not have left or right child, take -1 in its place.
Output format
Each level linked list is printed in new line (elements separated by space).
Mirror the given binary tree. That is, right child of every nodes should become left and left should become right.
Reference Image
Note : You don't need to print or return the tree, just mirror it.
Input format
Line 1 : Elements in level order form (separated by space)
(If any node does not have left or right child, take -1 in its place)
Output format
Elements in level order form (Every level in new line)
Given a binary tree, find it's diameter which is the largest distance possible between any two nodes and height.
Input Format
A binary tree in level order format
Output
diameter and height
Remove all leaf nodes from a given Binary Tree. Leaf nodes are those nodes, which don't have any children.
Note : Root will also be a leaf node if it doesn't have left and right child. You don't need to print the tree, just remove all leaf nodes and return the updated root.
Input format
Elements in level order form (separated by space)
(If any node does not have left or right child, take -1 in its place)
Output Format
Elements are printed level wise, each level in new line (separated by space).
Given a binary tree, print the level order traversal. Make sure each level start in new line.
Input format
Elements in level order form (separated by space).
If any node does not have left or right child, take -1 in its place.
Output Format
Elements are printed level wise, each level in new line (separated by space).
Given a binary tree, print all nodes that donβt have a sibling.
Edit : Print the elements in different lines. And order of elements doesn't matter.
Input format
Elements in level order form (separated by space).
If any node does not have left or right child, take -1 in its place.
Output format
Print nodes separated by new line.
Given a binary tree, check if its balanced i.e. depth of left and right subtrees of every node differ by at max 1. Return true if given binary tree is balanced, false otherwise.
Input format
Elements in level order form (separated by space).
If any node does not have left or right child, take -1 in its place.
Output format
boolean
Given Postorder and Inorder traversal of a binary tree, create the binary tree associated with the traversals.You just need to construct the tree and return the root.
Note: Assume binary tree contains only unique elements.
Input format
Line 1 : n (Total number of nodes in binary tree)
Line 2 : Post order traversal
Line 3 : Inorder Traversal
Output Format
Elements are printed level wise, each level in new line (separated by space).
Given a binary tree, print the Inorder traversal of given tree.
In-order traversal: Left -> Root -> Right
Input Format
Elements in level order form (separated by space)
(If any node does not have left or right child, take -1 in its place)
Output Format
In-order traversal, elements separated by space
Given a binary tree, print the postorder traversal of given tree.
Post-order traversal: Left -> Right -> Root
Input Format
Elements in level order form (separated by space)
(If any node does not have left or right child, take -1 in its place)
Output Format
Post-order traversal, elements separated by space
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.