Server Side Programming Articles

Page 292 of 2109

Program to find minimum remove required to make valid parentheses in Python

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

When working with parentheses validation, we often need to remove the minimum number of invalid parentheses to make a string valid. A string with parentheses is considered valid when every opening parenthesis has a corresponding closing parenthesis in the correct order. Problem Statement Given a string containing parentheses '(' and ')' along with lowercase English characters, we need to remove the minimum number of parentheses to make the string valid. A valid parentheses string satisfies these criteria: The string is empty or contains only lowercase characters, or The string can be written as AB (A concatenated ...

Read More

Program to find numbers with same consecutive differences in Python

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

Given a number N (length of digits) and K (absolute difference), we need to find all N-digit numbers where the absolute difference between every two consecutive digits equals K. Numbers cannot have leading zeros except for the single digit 0. For example, if N = 4 and K = 7, valid numbers include 1818 (|1-8|=7, |8-1|=7, |1-8|=7) and 2929, but 0707 is invalid due to the leading zero. Algorithm Approach We use a breadth-first search (BFS) approach with a queue ? If N = 1, return all single digits [0, 1, 2, ..., 9] Initialize ...

Read More

Program to find how many swaps needed to sort an array in Python

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

Finding the minimum number of swaps needed to sort an array is a classic problem. We need to consider both ascending and descending order, then return the minimum swaps required. So, if the input is like nums = [2, 5, 6, 3, 4], then the output will be 2 because initially nums has [2, 5, 6, 3, 4]. If we swap numbers 6 and 4, the array will be [2, 5, 4, 3, 6]. Then, if we swap the numbers 5 and 3, the array will be [2, 3, 4, 5, 6]. So 2 swaps are needed to make ...

Read More

Program to find maximum value at a given index in a bounded array in Python

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

Suppose we have three values: n, index and maxSum. We need to construct an array nums and find the maximum possible value at nums[index] that satisfies the following conditions: Size of nums is n All elements in nums are positive |nums[i] - nums[i+1]|

Read More

Program to find partition array into disjoint intervals in Python

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

Given an array nums, we need to partition it into two disjoint subarrays called left and right such that: Each element in left subarray is less than or equal to each element in right subarray Both left and right subarrays are non-empty Left subarray has the smallest possible size We have to find the length of left after such a partitioning. So, if the input is like nums = [5, 0, 3, 8, 6], then the output will be 3 because left array will be [5, 0, 3] and right subarray will be [8, 6]. ...

Read More

Program to find maximum number of consecutive values you can make in Python

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

Suppose we have an array called coins with n elements, representing the coins that we own. The value of the ith coin is denoted as coins[i]. We can make some value x if we can select some of our n coins such that their values sum up to x. We have to find the maximum number of consecutive values that we can get with the coins starting from and including 0. So, if the input is like coins = [1, 1, 3, 4], then the output will be 10, because ? 0 = [] (empty selection) 1 ...

Read More

Program to find out the number of accepted invitations in Python

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

This is a bipartite matching problem where we need to find the maximum number of boy-girl pairs for a party. Each boy can invite multiple girls, but each girl can accept only one invitation. We'll use a depth-first search (DFS) approach to solve this matching problem. Problem Understanding Given an m × n matrix where m boys invite n girls: Matrix[i][j] = 1 means boy i sent an invitation to girl j Matrix[i][j] = 0 means no invitation was sent Each girl can accept at most one invitation We need to find the maximum number of ...

Read More

Program to find out the number of pairs of equal substrings in Python

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

Suppose we are given two strings, both made of lowercase alphabets. We have to find out the number of quadruples (p, q, r, s) satisfying the given conditions − 0

Read More

Program to sort out phrases based on their appearances in Python

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

Suppose we are given two lists: phrases that contains selected phrases and sentences that contains several sentences. We need to find which phrases appear in the sentences and sort the phrases based on their frequency of appearances. The phrase with the most appearances comes first. So, if the input is like phrases = ['strong', 'durable', 'efficient'], sentences = ['the product is durable and efficient', 'strong and durable', 'it is efficient', 'like it because it is efficient'], then the output will be ['efficient', 'durable', 'strong'] The phrase 'efficient' appears in 3 sentences (indices 0, 2, and 3), making it ...

Read More

Program to find out the buildings that have a better view in Python

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

Suppose, we are provided with an array that contains the heights of different buildings. The buildings are located on a line, and a building has a better view if it is not obstructed by another taller building. So provided the array containing heights, we have to find out the buildings that do not have other taller buildings to obstruct the view from them. The indices are returned from the array that satisfies the criteria. So, if the input is like height = [5, 6, 8, 7], then the output will be [2, 3]. The buildings in array index 0 ...

Read More
Showing 2911–2920 of 21,090 articles
« Prev 1 290 291 292 293 294 2109 Next »
Advertisements