Arnab Chakraborty has Published 4293 Articles

Program to generate tree using preorder and inorder traversal in python

Arnab Chakraborty

Arnab Chakraborty

Updated on 26-Nov-2020 07:51:32

230 Views

Suppose we have the preorder and inorder traversal of a binary tree. We have to recover the tree from these sequences. So if the preorder and inorder sequences are [3, 9, 20, 15, 7] and [9, 3, 15, 20, 7], then the tree will be:Let us see the steps:Define a ... Read More

Program to check whether given list of blocks are symmetric over x = y line or not in python

Arnab Chakraborty

Arnab Chakraborty

Updated on 26-Nov-2020 07:49:12

389 Views

Suppose we have a list of numbers called nums. And it is representing the height of square blocks, we have to check whether the shape is symmetric over the y = x line or not.So, if the input is like nums = [7, 5, 3, 2, 2, 1, 1], then ... Read More

Program to count number of consecutive lists whose sum is n in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 26-Nov-2020 07:46:21

357 Views

Suppose we have a number n, we have to find the number of lists of positive consecutive values that sum up to n.So, if the input is like n = 15, then the output will be 4, as The possible lists are: [1, 2, 3, 4, 5], [4, 5, 6], ... Read More

Program to find number of unique four indices where they can generate sum less than target from four lists in python

Arnab Chakraborty

Arnab Chakraborty

Updated on 26-Nov-2020 07:43:54

178 Views

Suppose we have four list of numbers A, B, C and D and also have another number target. We have to find the number of different unique indices i, j, k, l such that A[i] + B[j] + C[k] + D[l] ≤ target.So, if the input is like A = ... Read More

Program to print matrix elements in spiral order in python

Arnab Chakraborty

Arnab Chakraborty

Updated on 26-Nov-2020 07:39:27

2K+ Views

Suppose we have a 2D matrix mat. We have to print the matrix elements in a spiral way. At first starting from the first row (mat[0, 0]), print the whole content and then follow the last column to print, then the last row, and so on, thus it prints the ... Read More

Program to sort a given linked list into ascending order in python

Arnab Chakraborty

Arnab Chakraborty

Updated on 26-Nov-2020 07:34:29

5K+ Views

Suppose we have a linked list. We have to sort the list into ascending order.So, if the input is like [5, 8, 4, 1, 5, 6, 3], then the output will be [1, 3, 4, 5, 5, 6, 8, ]To solve this, we will follow these steps:values := a new ... Read More

Program to find number of items left after selling n items in python

Arnab Chakraborty

Arnab Chakraborty

Updated on 26-Nov-2020 07:31:35

3K+ Views

Suppose we have a list of numbers called items and another value n. A salesman has items in a bag with random IDs. The salesman can delete as many as n items from the bag. We have to find the minimum number of different IDs in the bag after n ... Read More

Program to find second deepest node in a binary tree in python

Arnab Chakraborty

Arnab Chakraborty

Updated on 26-Nov-2020 07:29:14

317 Views

Suppose we have a binary tree; we have to find the depth of the second deepest leaf. If there are multiple deepest leaves, the second deepest leaf node will be the next highest one. As we know the root has a depth of 0.So, if the input is likethen the ... Read More

Program to check whether leaves sequences are same of two leaves or not in python

Arnab Chakraborty

Arnab Chakraborty

Updated on 26-Nov-2020 07:21:57

114 Views

Suppose we have two binary trees; we have to check whether the sequence of leaves left-to-right in both trees are the same.So, if the input is likethen the output will be True as the sequence is [2, 6] for both trees.To solve this, we will follow these steps:c := a ... Read More

Program to reverse words separated by set of delimiters in python

Arnab Chakraborty

Arnab Chakraborty

Updated on 26-Nov-2020 07:16:15

381 Views

Suppose we have a string and a set of delimiters, we have to reverse the words in the string while the relative ordering of the delimiters should not be changed.So, if the input is like s = "Computer/Network:Internet|tutorialspoint" delims = ["/", ":", '|'], then the output will be tutorialspoint/Internet:Network|ComputerTo solve ... Read More

Advertisements