Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 140 of 377

Find the index which is the last to be reduced to zero after performing a given operation in Python

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

Given an array and a value K, we need to find which index will be the last element to reach zero after repeatedly performing a subtraction operation. In each operation, we subtract K from each non-zero element, and if any element becomes less than K, it's set to zero. Problem Understanding The operation works as follows ? Start from A[0] to A[N − 1], update each element as A[i] = A[i] − K If A[i] < K, then set A[i] = 0 Once an element becomes 0, no further operations are performed on it Repeat until ...

Read More

Find the element before which all the elements are smaller than it, and after which all are greater in Python

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

In array processing, we sometimes need to find a special element that acts as a pivot point — an element where all elements to its left are smaller, and all elements to its right are greater. This problem requires finding such an element and returning its index, or -1 if no such element exists. Problem Understanding Given an array, we need to find an element where: All elements before it are smaller than the element All elements after it are greater than the element For the array [6, 2, 5, 4, 7, 9, 11, 8, ...

Read More

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

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 150 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 315 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 858 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 404 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 968 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 935 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 822 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 432 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
Showing 1391–1400 of 3,768 articles
« Prev 1 138 139 140 141 142 377 Next »
Advertisements