Server Side Programming Articles

Page 545 of 2109

Find the distance covered to collect items at equal distances in Python

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

In this problem, we need to calculate the total distance covered by a participant who collects stones placed at equal intervals and returns each stone to a starting bucket. The setup is as follows: A bucket is placed at the starting point The first stone is 6 units away from the bucket Each subsequent stone is 4 units apart from the previous one The participant must collect stones one by one, returning to the bucket after each collection Bucket ...

Read More

Find the count of sub-strings whose characters can be rearranged to form the given word in Python

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

Given a string S (all letters are lowercase), we need to find the count of all substrings of length four whose characters can be rearranged to form the word "bird". For example, if the input is "birdb", the output will be 2 because there are two 4-character substrings that contain exactly one 'b', one 'i', one 'r', and one 'd'. Approach To solve this problem, we follow these steps − Initialize a counter to 0 Iterate through all possible 4-character substrings For each substring, count occurrences of 'b', 'i', 'r', 'd' If each character appears ...

Read More

Find the cordinates of the fourth vertex of a rectangle with given 3 vertices in Python

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

A rectangle has four vertices, and if we know three of them, we can find the fourth by using the property that opposite vertices share the same coordinates. In a grid representation with asterisks ('*') marking three vertices, we need to find the missing fourth vertex coordinates. Problem Understanding Given a grid where exactly three asterisks ('*') represent three vertices of a rectangle, we need to find the coordinates of the fourth vertex. The key insight is that in a rectangle, each row and column should contain exactly two vertices, except for the missing vertex's row and column ...

Read More

Find the character in first string that is present at minimum index in second string in Python

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

Suppose we have a string str and another string patt, we need to find the character in patt that is present at the minimum index in str. If no character from patt is present in str, then return -1. For example, if str = "helloworld" and patt = "wor", the output will be 'o' because 'o' appears at index 4, which is the smallest index among all characters from patt that exist in str. Algorithm Steps To solve this problem, we follow these steps − Initialize minimum_index to a large value ...

Read More

Find sum of all elements in a matrix except the elements in row and-or column of given cell in Python

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

We have a 2D matrix and a set of cell indices represented as (i, j) where i is the row and j is the column. For each given cell index, we need to find the sum of all matrix elements excluding the elements in the ith row and jth column. For example, if we have the matrix: 2 2 3 4 5 7 6 4 3 And cell indices = [(0, 0), (1, 1), (0, 1)], the output will be [19, 14, 20]. Algorithm To ...

Read More

Find substrings that contain all vowels in Python

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

Sometimes we need to find all substrings within a string that contain all vowels (a, e, i, o, u) at least once and contain no consonants. This is useful for text processing and pattern matching tasks. Problem Statement Given a string in lowercase alphabets, we need to find all substrings that: Contain all five vowels at least once Contain no consonants For example, if the input is "helloworldaeiouaieuonicestring", the output will be substrings like 'aeiou', 'aeioua', 'aeiouai', etc. Algorithm We'll use a nested loop approach with these steps: For each ...

Read More

Find subsequences with maximum Bitwise AND and Bitwise OR in Python

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

When working with arrays and bitwise operations, we often need to find subsequences that maximize the sum of bitwise AND and OR operations. The key insight is that the maximum AND value comes from the largest single element, while the maximum OR value comes from combining all elements. Problem Understanding Given an array of n elements, we need to find two subsequences (possibly different) such that the sum of the bitwise AND of the first subsequence and bitwise OR of the second subsequence is maximized. For example, with array A = [4, 6, 7, 2], the maximum ...

Read More

Find sub-arrays from given two arrays such that they have equal sum in Python

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

When working with two arrays, you may need to find sub-arrays that have equal sums. This problem involves finding contiguous elements from each array where the sum of elements in one sub-array equals the sum in another sub-array. Given two arrays P and Q of size N containing numbers 1 to N, we need to find sub-arrays with equal sums and return their indices. If no solution exists, return -1. Example For arrays P = [2, 3, 4, 5, 6] and Q = [9, 3, 2, 6, 5], the solution is: P[0..2] = 2 + 3 ...

Read More

Find Shortest distance from a guard in a Bankin Python

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

Suppose we have a matrix filled with three letters 'O', 'G', and 'W' where 'O' represents open space, 'G' represents guards, and 'W' represents walls in a bank. We need to replace all O's with their shortest distance from the nearest guard, without going through walls. In the output matrix, guards become 0 and walls become -1. Problem Example If the input matrix is: OOOOG OOOWO OWOOO GWWWO OOOOG The output will be: 33210 233-11 1-1432 0-1-1-11 12210 Algorithm Approach We use multi-source BFS (Breadth-First Search) to solve this ...

Read More

Find same contacts in a list of contacts in Python

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

Finding duplicate contacts in a list is a common problem where we need to group contacts that belong to the same person. Two contacts are considered the same if they share any common field: username, email, or phone number. This problem can be solved using graph theory with Depth First Search (DFS). We create an adjacency matrix where contacts are nodes, and edges connect contacts that share any field. Problem Statement Given a list of contacts with three fields each (username, email, phone), we need to ? A contact can store username, email and phone ...

Read More
Showing 5441–5450 of 21,090 articles
« Prev 1 543 544 545 546 547 2109 Next »
Advertisements