Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 279 of 377

Program to find out if a linked list is present in a given binary tree in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 19-Oct-2021 250 Views

Suppose we are given a binary tree that has a root node 'root' and a linked list that has a head node 'head'. We have to find out if that linked list exists in that binary tree. If a set of nodes in the tree have links with each other in order as a linked list, and if that order is similar to that of the provided linked list, then we return 'True' or otherwise, we return 'False'.So, if the input is likeTreeLinked Listthen the output will be True.To solve this, we will follow these steps −arr := a new ...

Read More

Program to find out the largest sum value of a BST in a given binary tree in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 19-Oct-2021 250 Views

Suppose we are provided a binary tree. We have to find out if there exist binary search trees (BST) in the subtrees of it and find out the sum of the largest BST. To find out the sum, we add the values of each node in that BST. We return the sum value as output.So, if the input is likethen the output will be 12.The BST in the given binary tree is −sum of the nodes = 12.To solve this, we will follow these steps −c := 0m := nullvalue := 0Define a function recurse() . This will take nodeif ...

Read More

Program to find out if a BST is present in a given binary tree in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 19-Oct-2021 212 Views

Suppose we are given a binary tree. We have to find out the largest subtree from the tree that is a binary search tree (BST). We return the root node of the BST.So, if the input is likethen the output will be −To solve this, we will follow these steps −c := 0m := nullDefine a function recurse() . This will take nodeif node is not null, thenleft_val := recurse(left of node)right_val := recurse(right of node)count := negative infinityif (node.left is same as null or node.left.val

Read More

Program to find out the k-th smallest difference between all element pairs in an array in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 19-Oct-2021 425 Views

Suppose we are given a list containing several integer numbers. We have to find out the difference between each pair of values in the array and find out the k-th smallest difference number. The index starts at 0 and the value k is given to us as input.So, if the input is like numbers = {2, 6, 4, 8}, k = 2, then the output will be 2.The differences between the pairs are −(2, 6) = 4(2, 4) = 2(2, 8) = 6(6, 4) = 2(6, 8) = 2(4, 8) = 4If we sort the values, it becomes 2, 2, ...

Read More

Program to find out the k-th largest product of elements of two arrays in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 19-Oct-2021 278 Views

Suppose we are given two lists, p and q that contain some integer numbers. We have to multiply all the values of these lists and have to find out the k-th largest value from the multiplication results.So, if the input is like p = [2, 5], q = [6, 8], k = 2, then the output will be 16.The multiplication results are: 2 * 6 = 12, 2 * 8 = 16, 5 * 6 = 30, 5 * 8 = 40. The 2nd largest element at is (index starts from 0) is 16.To solve this, we will follow these ...

Read More

Program to find how many lines intersect in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 19-Oct-2021 588 Views

Suppose we are given a list that contains values in pairs of (m, c). These values represent a line, where y = mx + c. We are also given two values, l, and r. We have to find out the number of the lines that intersect with each other between the range x = l to x = h.So, if the input is like input_list = [[4, 6], [-6, 10], [8, 12]], l = 0, h = 2, then the output will be 2.If we look at the given photo, the lines 4x + 6 = 0 and -6x + ...

Read More

Program to find out the total number of characters to be changed to fix a misspelled word in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 19-Oct-2021 209 Views

Suppose we are given a list of cities and a list of roads that connect each other. The list 'cities' contain the name of cities that a tour bus visits in order. In the list 'roads' the roads are listed in a (source, destination) order meaning there is a one-way road from source to destination. Now, there is a problem that some city names in the list 'cities' may be misspelled. We have to correct such misspelled city names by changing the minimum number of characters. We return the number of characters changed as output.So, if the input is like ...

Read More

Program to decode a given message in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 19-Oct-2021 1K+ Views

Suppose we are given an encoded message that is a string of integer numbers. Now, these integer numbers can be mapped to a specific letter in the alphabet. a is mapped to 1, b is mapped to 2, c is mapped to 3, and so on. There is also a character '*' that can be in the message and that can be mapped to any of the numbers from 1 to 9. So given a message 'input', we have to find out how many ways it can be decoded.So, if the input is like input = "18", then the output ...

Read More

Program to find out the cost to merge an array of integers into a single value in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 19-Oct-2021 185 Views

Suppose we are given an array arr that contains n positive integer numbers. We are also given an integer number j. The task we have to perform is to merge j numbers into a single number by adding them. The cost of merging is equal to the addition of the j numbers we have selected. We have to find out the minimum possible cost for this merging operation.So, if the input is like arr = [2, 5, 6, 2, 3, 1, 3], j = 4, then the output will be 31.Cost to merge 2, 3, 1, 3 is equal to ...

Read More

Program to find length of longest repeating substring in a string in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 19-Oct-2021 3K+ Views

Suppose we have a lowercase string s, we have to find the length of the longest substring that occurs at least twice in s. If we cannot find such string, return 0.So, if the input is like s = "abdgoalputabdtypeabd", then the output will be 3, because the longest substring that occurs more than once is "abd".To solve this, we will follow these steps −Define a function lcs() . This will take s1, s2n := minimum of size of s1 and size of s2for i in range 0 to n - 1, doif s1[i] is not same as s2[i], thenreturn ...

Read More
Showing 2781–2790 of 3,768 articles
« Prev 1 277 278 279 280 281 377 Next »
Advertisements