Programming Articles

Page 109 of 2547

Program to Find Out the Strings of the Same Size in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 198 Views

In Python, we can solve the problem of finding strings of the same size with specific constraints using dynamic programming with memoization. Given a string and a maximum allowed consecutive character count, we need to find how many strings are lexicographically smaller or equal to the input string while satisfying the consecutive character limit. Problem Understanding Given a string s of lowercase letters and an integer k, we need to count strings that: Have the same length as s Are lexicographically smaller than or equal to s Have no more than k consecutive equal characters ...

Read More

Program to Find Out the Number of Squares in a Grid in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 752 Views

Suppose we have two values p and q, we have to find the number of unique squares that can be generated from a grid with p rows and q columns in which the points are placed evenly. If the answer is very large return result mod 10^9 + 7. In this problem, a square is a set of 4 points that form the four vertices of a square. The sides of the square must have the same length, and it does not always have to be aligned with the axes of the grid. So, if the input is ...

Read More

Program to Find Out the Special Nodes in a Tree in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 635 Views

A tree has special nodes where every node in its subtree has a unique color. Given an n-ary tree as an adjacency list and node colors, we need to count how many nodes are special. For each node i: tree[i] contains its children and parent color[i] represents its color value A node is "special" if all nodes in its subtree (including itself) have distinct colors ? Example Consider this tree structure: .node-circle { fill: #e3f2fd; stroke: #1976d2; ...

Read More

Program to Find Out if There is a Short Circuit in Input Words in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 176 Views

Given a list of words, we need to check if they can be chained to form a circle. A word A can be placed before word B if the last character of A matches the first character of B. Each word must be used exactly once. For example, with words = ["ant", "dog", "tamarind", "nausea", "gun"], we can form: ant → tamarind → dog → gun → nausea → ant (circle completed). Algorithm This problem is solved using graph theory concepts ? Build a directed graph where each character is a node Add edges from ...

Read More

Program to Find Out if an Edge is a Part of a Minimum Spanning Tree in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 487 Views

Suppose we have a 2D matrix named edges, that represents an undirected graph. Every item in the matrix edges represents an edge and is of the form (u, v, w). This means nodes u and v are connected and the edge has the weight w. We also have integers a and b, that represent an edge (a, b). We have to find out if the edge (a, b) is part of a minimum spanning tree. Note − the graph has to be connected and the edge (a, b) exists in the graph. So, if the input is like ...

Read More

Program to Find Out the Minimal Submatrices in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 333 Views

Suppose we have a 2D matrix and another value k. Our goal is to return a matrix that contains the minimum values of all k x k sub-matrices. So, if the input is like ? 3 5 6 8 6 5 ...

Read More

Program to find sum of widths of all subsequences of list of numbers in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 204 Views

Given a list of numbers, we need to find the sum of widths of all subsequences. The width of a subsequence is the difference between its maximum and minimum elements. We'll calculate this sum modulo 10^9 + 7 to handle large results. So, if the input is like nums = [7, 4, 9], then the output will be 15. The subsequences are: [7], [4], [9], [7, 4], [7, 9], [4, 9], [7, 4, 9] with widths 0, 0, 0, 3, 2, 5, 5 respectively, giving us a sum of 15. Algorithm To solve this efficiently, we follow ...

Read More

Program to find number of sublists containing maximum and minimum after deleting only one element in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 275 Views

Given a list of numbers, we can delete at most one element to maximize the number of sublists containing both the maximum and minimum values of the resulting list. This problem requires analyzing different scenarios when removing elements. Problem Understanding For the input nums = [3, 2, 6, 2, 4, 10], if we remove 10, we get [3, 2, 6, 2, 4] where min=2 and max=6. There are 8 sublists containing both values ? [2, 6] at indices (1, 2) [6, 2] at indices (2, 3) [2, 6, 2] at indices (1, 3) [3, 2, 6] ...

Read More

Program to find size of sublist where product of minimum of A and size of A is maximized in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 193 Views

Given a list of numbers called nums and an index pos, we need to find a sublist that includes the element at index pos such that (minimum of sublist) × (size of sublist) is maximized. For example, if nums = [-2, 2, 5, 4] and pos = 3, the best sublist is [5, 4] (indices 2-3). The minimum is 4, size is 2, so the product is 4 × 2 = 8. Algorithm We use a greedy approach to expand the sublist from the given position ? Start with the element at pos as both ...

Read More

Program to expand string represented as n(t) format in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 424 Views

String expansion in the n(t) format is a common programming problem where we need to decode compressed strings. The format n(t) means concatenate string t exactly n times, and t can be either a regular string or another encoded string recursively. So, if the input is like s = "3(pi)2(3(am))0(f)1(u)", then the output will be "pipipiamamamamamamu". Algorithm Steps To solve this problem, we will follow these steps − Initialize index i := 0 Define a recursive function parse() that processes the string Create an empty result list While i < string length and current character ...

Read More
Showing 1081–1090 of 25,469 articles
« Prev 1 107 108 109 110 111 2547 Next »
Advertisements