Posts

Showing posts from November, 2020

Docker command cheatsheet

Image
The reason for creating this cheat sheet is because a long time ago I was called for an interview and he asked me some basic command questions regarding docker and in reply, I said "I forget the actual command 😑" yeah you read it right I know it sounds not good so for the next time I make sure this won't happen again in my life that is why I wrote down below some basic commands that every docker user should know. Hope this cheat sheet is also helpfully for you.😀 To see all commands of docker  Write down  docker on the command line. You will see all the commands of docker in the image below. Get the status of the docker daemon Docker information:- docker info C reate a container without  starting It Creates container:- docker create [image name] Docker run commands  Run container:- docker run [image name] Run container with specified image version:- docker run [image name]:[version] Docker run in background/detach mode image :- docker run -d [image name] Docker...

Level order traversal

Image
For a given a Binary Tree of type integer, print it in a level order fashion where each level will be printed on a new line. Elements on every level will be printed in a linear fashion and a single space will separate them. Example: For the above-depicted tree, when printed in a level order fashion, the output would look like: 10 20 30 40 50 60 Where each new line denotes the level in the tree. Input Format: The first and the only line of input will contain the node data, all separated by a single space. Since -1 is used as an indication whether the left or right node data exist for root, it will not be a part of the node data. Output Format: The given input tree will be printed in a level order fashion where each level will be printed on a new line. Elements on every level will be printed in a linear fashion. A single space will separate them. Constraints: 1 <= N <= 10^5 Where N is the total number of nodes in the binary tree. Time Limit: 1 sec Sample Input 1: 10 20 30 40 50...

Path Sum Root to Leaf

Image
For a given Binary Tree of type integer and a number K, print out all root-to-leaf paths where the sum of all the node data along the path is equal to K. Example: If you see in the above-depicted picture of Binary Tree, we see that there are a total of two paths, starting from the root and ending at the leaves which sum up to a value of K = 13. The paths are: a. 2 3 4 4 b. 2 3 8 One thing to note here is, there is another path in the right sub-tree in reference to the root, which sums up to 13 but since it doesn't end at the leaf, we discard it. The path is: 2 9 2(not a leaf)  Input Format: The first line of input will contain the node data, all separated by a single space. Since -1 is used as an indication whether the left or right node data exist for root, it will not be a part of the node data. The second line of input contains an integer value K. Output Format: Lines equal to the total number of paths will be printed. All the node data in every path will be printed in a line...

Create & Insert Duplicate Node

Image
For a given a Binary Tree of type integer, duplicate every node of the tree and attach it to the left of itself. The root will remain the same. So you just need to insert nodes in the given Binary Tree. Example: After making the changes to the above-depicted tree, the updated tree will look like this. You can see that every node in the input tree has been duplicated and inserted to the left of itself. Input format : The first and the only line of input will contain the node data, all separated by a single space. Since -1 is used as an indication whether the left or right node data exist for root, it will not be a part of the node data. Output Format : The updated tree will be printed in a level order fashion where each level will be printed on a new line. Elements on every level will be printed in a linear fashion. A single space will separate them.  Note: You are not required to print anything explicitly. It has already been taken care of. Just implement the function to achieve t...

Minimum and Maximum in the Binary Tree

For a given a Binary Tree of type integer, find and return the minimum and the maximum data values. Return the output as an object of Pair class, which is already created. Note: All the node data will be unique and hence there will always exist a minimum and maximum node data. Input Format: The first and the only line of input will contain the node data, all separated by a single space. Since -1 is used as an indication whether the left or right node data exist for root, it will not be a part of the node data. Output Format: The only line of output prints two integers denoting the minimum and the maximum data values respectively. A single line will separate them both. Constraints: 2 <= N <= 10^5 Where N is the total number of nodes in the binary tree. Time Limit: 1 sec Sample Input 1: 8 3 10 1 6 -1 14 -1 -1 4 7 13 -1 -1 -1 -1 -1 -1 -1 Sample Output 1: 1 14 Sample Input 2: 10 20 60 -1 -1 3 50 -1 -1 -1 -1 Sample Output 2: 3 60

Popular posts from this blog

MySQL Multi Source Master Slave Replication using GTID

Access and modify all the resources of our Wiki.js using WikiJS API

How to pass parameters in webhook?