Articles on Trending Technologies

Technical articles with clear explanations and examples

Program to find out the palindromic borders in a string in python

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

A palindromic border is a substring that appears as both a prefix and suffix of a string, and the substring itself is a palindrome. For example, in the string 'ababab', the substring 'ab' is a border, but not palindromic. However, in 'pqpqp', the substring 'p' is both a border and palindromic. Given a string, we need to find the sum of palindromic borders across all possible substrings. The result should be returned modulo 10^9 + 7. Example For the string 'pqpqp', there are 15 total substrings, but only 4 have palindromic borders ? pqp : ...

Read More

Program to find expected value of maximum occurred frequency values of expression results in Python

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

When analyzing M expressions with results ranging from 1 to N, we need to find the expected value of the maximum frequency among all possible outcomes. This problem involves calculating probabilities using combinatorics and the inclusion-exclusion principle. Problem Understanding Given M expressions with results in range [1, N], we want to find the expected value of the maximum frequency. For each possible sequence of expression results, we count the frequency of the most common value. For example, with M = 3, N = 3: Sequence Maximum Frequency 1113 1122 1132 1212 1222 1231 ...

Read More

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 308 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 506 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 356 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 509 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 292 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 220 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

How to curve text in a polar plot in matplotlib?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 26-Mar-2026 990 Views

Creating curved text in a polar plot requires plotting lines along curved paths and positioning text elements along angular coordinates. This technique is useful for creating circular labels, curved annotations, and artistic text layouts in matplotlib polar plots. Basic Setup First, let's create a basic polar plot with curved lines ? import matplotlib.pyplot as plt import numpy as np from scipy.interpolate import interp1d plt.rcParams["figure.figsize"] = [8, 6] plt.rcParams["figure.autolayout"] = True fig = plt.figure() ax = fig.add_subplot(111, projection="polar") # Create radial lines at specific angles for degree in [0, 90, 180, 270]: ...

Read More

Matplotlib – Difference between plt.subplots() and plt.figure()

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 26-Mar-2026 2K+ Views

In Matplotlib, plt.figure() and plt.subplots() are two fundamental functions for creating plots, but they serve different purposes and return different objects. Understanding plt.figure() plt.figure() creates a new figure object or activates an existing one. It returns a Figure object but doesn't create any axes by default. import matplotlib.pyplot as plt import numpy as np # Create a figure using plt.figure() fig = plt.figure(figsize=(8, 5)) fig.suptitle("Using plt.figure()") # Add data manually using plt.plot() x = np.linspace(0, 10, 50) y = np.sin(x) plt.plot(x, y, 'b-', label='sin(x)') plt.xlabel('X values') plt.ylabel('Y values') plt.legend() plt.grid(True) plt.show() ...

Read More
Showing 3181–3190 of 61,299 articles
« Prev 1 317 318 319 320 321 6130 Next »
Advertisements