Server Side Programming Articles

Page 489 of 2109

Program to find number of subsequence that are present inside word list in python

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

Given a list of words and a string s, we need to find how many words are subsequences of s. A subsequence maintains the relative order of characters but doesn't need to be contiguous. So, if the input is like words = ["xz", "xw", "y"] and s = "xyz", then the output will be 2, as "xz" and "y" are subsequences of "xyz". Algorithm To solve this, we will follow these steps − Initialize ans := 0 and create an empty dictionary d Group words by their first character in dictionary d For each character ...

Read More

Program to find minimum number of subsequence whose concatenation is same as target in python

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

Suppose we have two strings source and target, we have to find the minimum number of subsequences of source we can form such that if we concatenate them, it will be same as target. If there is no such result, return -1. So, if the input is like source = "xyz" target = "xyzyzz", then the output will be 3, as we can concatenate these ["xyz" + "yz" + "z"] Algorithm To solve this, we will follow these steps − s_size := size of s, t_size := size of t concat_count := 0, target_idx := ...

Read More

Program to list of candidates who have got majority vote in python

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

Suppose we have a list of numbers called nums where each number represents a vote to a candidate. We have to find the ids of the candidates that have greater than floor(n/3) votes, in non-decreasing order. So, if the input is like nums = [3, 2, 6, 6, 6, 6, 7, 7, 7, 7, 7], then the output will be [6, 7], as 6 and 7 have more than 33% of the votes (4 out of 11 and 5 out of 11 respectively). Algorithm To solve this, we will follow these steps − ans := ...

Read More

Program to count maximum number of strings we can generate from list of words and letter counts in python

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

Suppose we have a list of strings where each string contains only letters "A"s and "B"s. We have two values a and b. We have to find the maximum number of strings that can be formed using at most a number of "A"s and at most b number of "B"s, without reusing strings. So, if the input is like strings = ["AAABB", "AABB", "AA", "BB"], a = 4, b = 2, then the output will be 2, as we can take the strings using 4 "A"s and 2 "B"s: ["AABB", "AA"]. Approach To solve this, we will ...

Read More

Program to count number of stepping numbers of n digits in python

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

A stepping number is a number where all adjacent digits have an absolute difference of exactly 1. For example, 123 is a stepping number (|1-2|=1, |2-3|=1), but 124 is not (|2-4|=2). We need to count all stepping numbers with exactly n digits. Understanding the Problem For n = 2, the stepping numbers are: [10, 12, 21, 23, 32, 34, 43, 45, 54, 56, 65, 67, 76, 78, 87, 89, 98], giving us 17 total numbers. Dynamic Programming Approach We use dynamic programming where dp[i] represents the count of stepping numbers ending with digit i. For each ...

Read More

Program to find the size of the longest sublist where car speed is constant in python

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

Suppose we have a list of numbers representing the position of a car at equally spaced intervals of time. We have to find the size of the longest sublist where the car was traveling at a constant speed. So, if the input is like positions = [0, 4, 8, 12, 6, 4, 0], then the output will be 4, as the sublist is [0, 4, 8, 12]. Algorithm To solve this, we will follow these steps − j := 1 max_cnt := 0, current := 0 ...

Read More

Program to check given push pop sequences are proper or not in python

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

When working with stack operations, we often need to validate whether a given sequence of push and pop operations is possible. This problem involves checking if two sequences represent valid stack push and pop actions. Given two lists pushes and pops, we need to determine if we can simulate the push operations in order while achieving the exact pop sequence specified. Example Scenario If we have pushes = [1, 2, 5, 7, 9] and pops = [2, 1, 9, 7, 5], this is valid because we can: Push 1, then push 2, then pop 2, ...

Read More

Program to find number of square submatrices with 1 in python

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

Suppose we have a 2D binary matrix, we have to find the total number of square submatrices with all 1s. This problem can be solved using dynamic programming by tracking the largest square ending at each position. So, if the input is like: 1 ...

Read More

Program to find final states of rockets after collision in python

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

We have a list of numbers representing rocket sizes and directions. Positive integers indicate rightward movement, negative numbers indicate leftward movement. The absolute value represents the rocket's size. When rockets collide, the smaller one is destroyed, and equal-sized rockets both get destroyed. Problem Understanding Given rockets moving in opposite directions, we need to simulate collisions and find the final state. Rockets moving in the same direction never collide. Example For nums = [3, 8, 5, -5], rockets 5 (right) and -5 (left) collide and both are destroyed, leaving [3, 8]. Algorithm We'll use a ...

Read More

Program to find minimum space plane required for skydivers in k days in python

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

Suppose we have a list of numbers called nums where each value represents a group of people looking to skydive together. And we have another value k representing how many days they can apply for skydiving. We have to find the minimum capacity of the plane we need to be able to fulfill all requests within k days. The requests should be fulfilled in the order they were given and a plane can only fly once a day. So, if the input is like nums = [16, 12, 18, 11, 13], k = 3, then the output will be ...

Read More
Showing 4881–4890 of 21,090 articles
« Prev 1 487 488 489 490 491 2109 Next »
Advertisements