Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 80 of 377

Program to find length of longest common subsequence in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 285 Views

Suppose we have two strings text1 and text2, we have to find the length of their longest common subsequence. As we know a subsequence of a string is a new string generated from the original string with some characters deleted without changing the relative order of the remaining characters. (So for example "abe" is a subsequence of "abcde" but "adc" is not). A common subsequence of two strings is a subsequence that is common to both strings. So If there is no common subsequence, return 0. If the input is like “abcde”, and “ace”, then the result will be 3.To ...

Read More

Program to encrypt a string using Vigenere cipher in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 5K+ Views

Suppose we have a lowercase alphabet string text, and have another string called key. We have to find a new string where every letter in text[i] is moved to the right side with offset key[i]. Here the offset represented by key[i]'s position in the alphabet (A=0, B=1 etc.) If the letter overflows, it gets wrapped around the other side.So, if the input is like text = "code", key = "team", then the output will be "vsdq"To solve this, we will follow these steps −cip := a new liststart := ASCII of 'a'for each l from text and k from key, ...

Read More

Program to find length of longest common substring in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 2K+ Views

Suppose we have two lowercase strings X and Y, we have to find the length of their longest common substring.So, if the input is like X = "helloworld", Y = "worldbook", then the output will be 5, as "world" is the longest common substring and its length is 5.To solve this, we will follow these steps −Define an array longest of size: m+1 x n+1.len := 0for initialize i := 0, when i

Read More

Program to sort all vowels at beginning then the consonants, are in sorted order in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 2K+ Views

Suppose we have a lowercase alphabet string s, we have to find a string with all the vowels of s in sorted sequence followed by all consonants of s in sorted sequence.So, if the input is like "helloworld", then the output will be "eoodhlllrw", as vowels are "eo" And consonants are in sorted order "dhlllrw"To solve this, we will follow these steps −k := blank string, t := blank stringfor each character c in s, doif c is a vowel, thenk := k concatenate cotherwise, t := t concatenate creturn (k after sort and concatenate t after sorting)Let us see ...

Read More

Program to find the maximum profit we can get by buying on stock market once in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 1K+ Views

Suppose we have a list of prices representing the stock prices of a company in chronological sequence, we have to find the maximum profit we could have made from buying and selling that stock only once. We have to keep in mind that we must buy before we can sell it.So, if the input is like prices = [10, 12, 9, 6, 8, 12], then the output will be 6, as we can buy at 6 and sell at 12.To solve this, we will follow these steps −max_profit := 0min_stock := infinityfor each price in prices, domax_profit := maximum of ...

Read More

Program to check whether given graph is bipartite or not in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 886 Views

Suppose we have one undirected graph, we have to check whether the graph is bipartite or not. As we know a graph is bipartite when we can split the nodes of the graph into two sets A and B such that every edge {u, v} in the graph has one node u in A and another node v in B.So, if the input is likeThen the output will be True, [0, 4] are in set A and [1, 2, 3] are in set B, and all edges are from A to B or B to A, not A to A ...

Read More

Program to find the maximum profit we can get by buying on stock market multiple times in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 343 Views

Suppose we have a list of prices representing the stock prices of a company in chronological sequence, we have to find the maximum profit we could have made from buying and selling that stock any number of times. We have to keep in mind that we must buy before we can sell it.So, if the input is like prices = [10, 50, 30, 40, 60], then the output will be 70, as We can buy at 10, sell at 50, buy at 30, and sell at 60.To solve this, we will follow these steps −prev_price := infinityprofit := 0for each ...

Read More

Program to check we can spell out the target by a list of words or not in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 233 Views

Suppose we have a list of numbers called nums and another number k. If we start at index k and at any index i, we can go either left or right by exactly nums[i] number of steps. We have to check whether we can reach the end of the list or not.So, if the input is like nums = [0, 0, 2, 1, 3, 3, 1, 1] k = 2, then the output will be True, as if we start at index 2, then jump to index 4 and then jump to the last index 7.To solve this, we will ...

Read More

Program to find the sum of elements that forms a Z shape on matrix in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 486 Views

Suppose we have one n x n matrix M, we have to find the sum of all elements that form a Z shape in the matrix.So, if the input is like432918256then the output will be 23, as elements are [4+3+2+1+2+5+6] = 23.To solve this, we will follow these steps −n := row count of matrixif n

Read More

Program to find maximum amount we can get by taking different items within the capacity in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 617 Views

Suppose we have two lists called weights and values which are of same length and another number called capacity k. Here weights[i] and values[i] shows the weight and value of the ith item. Now, we can take at most k capacity weights, and that we can only take at most one copy of each item, we have to find the maximum amount of value we can get.So, if the input is like weights = [2, 3, 4], values = [2, 6, 4], capacity = 6, then the output will be 8To solve this, we will follow these steps −n:= size ...

Read More
Showing 791–800 of 3,768 articles
« Prev 1 78 79 80 81 82 377 Next »
Advertisements