Programming Articles

Page 143 of 2547

Program to find out the substrings of given strings at given positions in a set of all possible substrings in python

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

When working with multiple strings, we often need to find specific substrings from the union of all possible substrings. This involves generating all substrings from each string, creating a sorted union set, and retrieving elements at specified positions. So, if the input strings are ['pqr', 'pqt'] and queries are [4, 7, 9], then the output will be ['pqt', 'qt', 't']. How It Works The substrings from the first string are: {p, pq, pqr, q, qr, r} The substrings from the second string are: {p, pq, pqt, q, qt, t} The union of these sets is: {p, ...

Read More

Program to count number of isosceles triangle from colored vertex regular polygon in Python

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

In a regular polygon with n sides, we need to count isosceles triangles formed by vertices of the same color. The vertices are colored either blue (0) or red (1) represented as a binary string. An isosceles triangle has at least two sides of equal length. So, if the input is like polygon = "111010", then the output will be 2 because there are two triangles ACE and AFE as shown in the diagram ? A(1) B(1) ...

Read More

Program to find the indexes where the substrings of a string match with another string fully or differ at one position in python

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

When working with string matching problems, we often need to find substrings that either match exactly or differ by only one character. This article demonstrates how to find starting indexes in a string where substrings match another string completely or differ at exactly one position. Given two strings where the first string is longer than the second, we need to identify all starting positions where substrings from the first string either match the second string exactly or differ by only one character. Problem Example If we have string1 = 'tpoint' and string2 = 'pi', the output should ...

Read More

Program to find maximum possible value of an expression using given set of numbers in Python

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

We need to find the maximum possible value of an expression (sum1)² + (sum2)² where sum1 and sum2 are sums of elements from non-empty subsets of two arrays nums1 and nums2. Given two arrays with the same number of elements, we select indices and calculate the sum of corresponding elements from each array, then find the maximum value of the sum of their squares. Problem Understanding For arrays nums1 = [-1, 6] and nums2 = [5, 4], possible calculations are ? Using index 0: (-1)² + (5)² = 1 + 25 = 26 Using index ...

Read More

Program to find out the similarity between a string and its suffixes in python

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

In this problem, we need to find the similarity between a string and all its suffixes. The similarity is defined as the length of the longest common prefix between the original string and each suffix. We then sum up all these similarities. For example, if the string is 'abcd', the suffixes are 'abcd', 'bcd', 'cd', 'd'. We compare each suffix with the original string to find how many characters match from the beginning. Understanding the Problem Let's see how this works with the string 'tpotp' ? Original string: 'tpotp' Suffixes and their similarities: 'tpotp' → ...

Read More

Program to find out the letter at a particular index in a synthesized string in python

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

Suppose, we are given a string input_str. We need to find all possible substrings from the given string, then concatenate all the substrings in lexicographic order into another string. Given an integer value k, our task is to return the letter at index k from the concatenated string. So, if the input is like input_str = 'pqrs', k = 6, then the output will be 'p'. Understanding the Problem The substrings from the given string 'pqrs' in lexicographic order are: p, pq, pqr, pqrs, q, qr, qrs, r, rs, s. If we concatenate these strings, it ...

Read More

Program to find out the sum of numbers where the correct permutation can occur in python

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

Given a number n, we need to find all possible permutations of positive integers up to n, sort them lexicographically, and number them from 1 to n!. When some values in a "special permutation" are forgotten (replaced with 0s), we must find all permutations that could match the original and sum their lexicographic positions. For example, if the special permutation is [0, 2, 0] with n=3, the possible original permutations are [1, 2, 3] (position 2) and [3, 2, 1] (position 5), giving us a sum of 7. Algorithm Steps The solution uses factorial number system and ...

Read More

Program to determine the minimum cost to build a given string in python

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

Suppose we have to build a string str of length n. To build the string, we can perform two operations: Add a character to the end of str for cost a Add a substring that already exists in the current string for cost r We need to calculate the minimum cost of building the string str using dynamic programming. Example If the input is a = 5, r = 4, str = 'tpoint', then the output will be 29. To build the string 'tpoint', the ...

Read More

Program to find maximum score by splitting binary strings into two parts in Python

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

Suppose we have a binary string s. We need to split it into two non-empty substrings s1 and s2. The score of this split is the count of "0"s in s1 plus the count of "1"s in s2. We have to find the maximum score we can obtain. So, if the input is like s = "011001100111", then the output will be 8, because we can split the string like "01100" + "1100111". Then, the score is 3 + 5 = 8. Algorithm To solve this, we will follow these steps − ones := number ...

Read More

Program to find matrix for which rows and columns holding sum of behind rows and columns in Python

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

Given a matrix, we need to find a new matrix where each element at position res[i, j] contains the sum of all elements from the original matrix where row r ≤ i and column c ≤ j. This is known as calculating the prefix sum matrix or cumulative sum matrix. Problem Understanding For each position (i, j) in the result matrix, we sum all elements in the rectangle from (0, 0) to (i, j) in the original matrix. If the input matrix is ? 8 2 7 4 Then ...

Read More
Showing 1421–1430 of 25,469 articles
« Prev 1 141 142 143 144 145 2547 Next »
Advertisements