Arnab Chakraborty has Published 4293 Articles

Program to convert one list identical to other with sublist sum operation in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 19-Oct-2020 15:11:05

167 Views

Suppose we have two lists l1 and l2, we have to make the lists equal by applying this operation repeatedly − Choose a sublist, and replace the whole sublist with its sum. Finally return the size of the longest resulting list possible after applying above operations. If there's no solution, ... Read More

Program to check minimum number of characters needed to make string palindrome in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 12-Oct-2020 12:04:58

489 Views

Suppose we have a string s, we have to find the minimum number of characters needed to be inserted so that the string becomes a palindrome.So, if the input is like s = "mad", then the output will be 2, as we can insert "am" to get "madam".To solve this, ... Read More

Program to find an ancestor which is common of two elements in a binary tree in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 12-Oct-2020 12:01:59

248 Views

Suppose we have a binary tree, and we also have two numbers a and b, we have to find the value of the lowest node that has a and b as descendants. We have to keep in mind that a node can be a descendant of itself.So, if the input ... Read More

Program to find minimum length of lossy Run-Length Encoding in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 10-Oct-2020 15:03:03

293 Views

Suppose we have a lowercase string s and another value k. Now consider an operation where we perform a run-length encoding on a string by putting repeated successive characters as a count and character. So if the string is like "aaabbc" would be encoded as "3a2bc". Here we do not ... Read More

Program to find sum of longest sum path from root to leaf of a binary tree in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 10-Oct-2020 14:19:52

185 Views

Suppose we have a binary tree, we have to find the sum of the longest path from the root to a leaf node. If there are two same long paths, return the path with larger sum.So, if the input is likethen the output will be 20.To solve this, we will ... Read More

Program to find longest path between two nodes of a tree in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 10-Oct-2020 14:05:24

957 Views

Suppose we have a binary tree; we have to find the longest path between any two nodes in the tree.So, if the input is like then the output will be 5 To solve this, we will follow these steps:ans := 0Define a function getMaxPath() . This will take nodeif node is null, ... Read More

Program to find the length of longest substring which has two distinct elements in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 10-Oct-2020 13:57:29

563 Views

Suppose we have a string s, we have to find the length of the longest substring that contains at most 2 distinct characters.So, if the input is like s = "xyzzy", then the output will be 4, as "yzzy" is the longest substring with at most 2 unique characters.To solve ... Read More

Program to find length of longest sublist with given condition in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 10-Oct-2020 13:51:11

312 Views

Suppose we have a list of numbers called nums, we have to find the length of the longest sublist where 2 * minimum of sublist > maximum of sublist.So, if the input is like nums = [10, 2, 6, 6, 4, 4], then the output will be 4, as the ... Read More

Program to find length of longest palindromic substring in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 10-Oct-2020 13:41:59

643 Views

Suppose we have a string S. We have to find the length of longest palindromic substring in S. We are assuming that the length of the string S is 1000. So if the string is “BABAC”, then the longest palindromic substring is “BAB” and length is 3.To solve this, we ... Read More

Program to find length of longest alternating inequality elements sublist in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 10-Oct-2020 13:36:00

228 Views

Suppose we have a list of mumbers called nums, and find the length of the longest sublist in nums such that the equality relation between every consecutive numbers changes alternatively between less-than and greater-than operation. The first two numbers' inequality may be either less-than or greater-than.So, if the input is ... Read More

Advertisements