Arnab Chakraborty has Published 4452 Articles

Program to find out the lowest common ancestor of a binary tree using Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 28-May-2021 14:02:53

111 Views

Suppose, we are given a binary tree and also two specific nodes x and y. We have to find out the lowest common ancestor of the two nodes from the binary tree. The lowest common ancestor in a binary tree is the lowest node of which both the nodes x ... Read More

Program to find out the dot product of two sparse vectors in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 18-May-2021 12:14:56

541 Views

Suppose, we have two sparse vectors represented in two lists. We have to return the dot product of the two sparse vectors. The vectors are represented as objects, and the lists are stored in a member variable 'nums' in the objects.So, if the input is like vector1 = [1, 0, ... Read More

Program to find out the number of boxes to be put into the godown in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 18-May-2021 12:14:14

269 Views

Suppose, we have two arrays containing integers. One list contains the height of some unit width boxes and another array contains the height of rooms in the godown. The rooms are numbered 0...n, and the height of the rooms is provided in their respective indexes in the array godown. We ... Read More

Program to find out if the strings supplied differ by a character in the same position in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 18-May-2021 12:12:02

100 Views

Suppose, we are provided an array that contains several strings that are of the same length. We have to find out if any two of the supplied strings differ by a single character at the same position. If this difference is present, we return true or else we return false.So, ... Read More

Program to find out the index of the most frequent element in a concealed array in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 18-May-2021 12:08:02

173 Views

Suppose, we are given a class called 'TestArray' that contains an private array which can only contain values 0 or 1; and two public member functions length() and query(). The function length() returns the length of the array and the function query() returns three different values comparing various values in ... Read More

Program to find out the index in an array where the largest element is situated in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 18-May-2021 12:06:41

158 Views

Suppose, we are given a class called 'TestArray' that contains an array that is not accessible by other classes and two public member functions length() and compare(). The function length() returns the length of the array and the function compare() returns three different values comparing various subarrays from the array. ... Read More

Program to find the diameter of a n-ary tree in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 18-May-2021 12:05:16

291 Views

Suppose, we are given an n-ary tree and said to determine the diameter of the tree. The diameter of the tree is the longest path that is present between any two leaf nodes of the tree. We have to find out and return the integer value that represents the diameter ... Read More

Program to find the root of a n-ary tree in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 18-May-2021 12:04:53

506 Views

Suppose, we are given the nodes of an n-ary tree in an array. We have to find and return the root node of the tree by reconstructing it. The full tree has to be displayed from the returned node in preorder notation.So, if the input is likethen the output will ... Read More

Program to make a copy of a n-ary tree in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 18-May-2021 12:01:45

1K+ Views

Suppose, we have been provided a n-ary tree whose root is given to us 'root'. We have to make a copy of the full n-ary binary tree and perform a preorder traversal of both trees. The copied tree has to be stored using another root node. The node structure of ... Read More

Program to find minimum changes required for alternating binary string in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 18-May-2021 11:59:02

276 Views

Suppose we have a binary string s. Let us consider an operation where we can flip one bit. The string s is called alternating string if no two adjacent characters are same. We have to find the minimum number of operations needed to make s alternating.So, if the input is ... Read More

Advertisements