Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 7 of 377

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

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 225 Views

A Binary Search Tree (BST) is a special type of binary tree where the left subtree contains values less than or equal to the root, and the right subtree contains values greater than or equal to the root. This problem asks us to find the largest BST subtree within a given binary tree. Original Tree: 1 4 6 ...

Read More

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

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 290 Views

Given two lists containing integer numbers, we need to find the k-th largest product by multiplying each element from the first list with each element from the second list. This problem can be efficiently solved using a min-heap to track the k largest products. 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. When sorted in descending order: [40, 30, ...

Read More

Program to find how many lines intersect in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 600 Views

Sometimes we need to find how many lines intersect within a given range. Given a list of lines in the form (m, c) representing y = mx + c, we can determine which lines intersect between x = l and 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. ...

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 26-Mar-2026 220 Views

This problem involves finding the minimum number of character changes needed to correct misspelled city names in a tour route. Given a list of cities that a bus visits in order and a list of one-way roads connecting cities, we need to find valid paths and calculate the minimum corrections required. Problem Understanding The algorithm uses dynamic programming to find the optimal path through valid roads while minimizing character differences between the given city names and actual city names. Algorithm Steps The solution follows these key steps − Create a helper function to calculate ...

Read More

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

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 275 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 like ? 6 ...

Read More

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

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 3K+ Views

A repeating substring is a substring that occurs at least twice in a string. In this tutorial, we'll find the length of the longest repeating substring using Python's suffix array approach. 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". Algorithm Overview To solve this problem, we will follow these steps − Generate all suffixes of the string Sort the suffixes lexicographically Find the longest common prefix between adjacent suffixes Return the maximum length found Helper ...

Read More

Program to find length longest prefix sequence of a word array in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 277 Views

Suppose we have a list of words called w, with lowercase strings. We have to find the length of the longest sequence of w where each previous word is the prefix of the next word and the next word has just one new character appended. So, if the input is like w = ["pqr", "pq", "m", "mn", "pqrs"], then the output will be 3 because we can get the sequence: ["pq", "pqr", "pqrs"], whose length is 3. Algorithm To solve this, we will follow these steps − Sort the list w ...

Read More

Program to find length of longest consecutively increasing substring in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 289 Views

Given a lowercase string containing English letters and "?" symbols, we need to find the length of the longest consecutively increasing substring that starts with letter "a". For each "?" we can either remove it or replace it with any lowercase letter. For example, if the input is s = "vta???defke", we can transform it into "vtabcdefke" where "abcdef" is the longest consecutively increasing substring starting with "a", giving us a length of 6. Algorithm We'll use a greedy approach to track the current sequence length and question marks ? maxlen − Maximum length found ...

Read More

Program to find length of longest consecutive sublist with unique elements in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 419 Views

Suppose we have a list of numbers called nums, where all elements are unique. We have to find the length of the longest sublist that contains consecutive elements. So, if the input is like nums = [3, 6, 7, 5, 4, 9], then the output will be 5, because the sublist [3, 6, 7, 5, 4] contains all consecutive elements from 3 to 7. Algorithm Approach To solve this, we will follow these steps − Initialize ret := 0 to store the maximum length For each starting ...

Read More

Program to find longest consecutive run of 1s in binary form of n in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 781 Views

Suppose we have a non-negative value n, we have to find the length of the longest consecutive run of 1s in its binary representation. So, if the input is like n = 1469, then the output will be 4, because binary representation of 1469 is "10110111101", so there are four consecutive 1s. Approach To solve this, we will follow these steps ? count := 0 while n is not same as 0, do n := n AND (n after shifting one bit to the left) count := count + 1 return count How It Works The algorithm uses bit manipulation where n & (n

Read More
Showing 61–70 of 3,768 articles
« Prev 1 5 6 7 8 9 377 Next »
Advertisements