Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 10 of 377

Minimum number of moves to escape maze matrix in Python

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

Suppose we have a binary matrix, where 0 represents an empty cell, and 1 is a wall. Starting from the top left corner (0, 0), we need to find the minimum number of cells to reach the bottom right corner (R-1, C-1), where R is the number of rows and C is the number of columns. If no path exists, return -1. This is a classic shortest path problem that can be solved using Breadth-First Search (BFS). Problem Example If the input matrix is like ? 00010 00110 00011 11000 Then the output ...

Read More

Program to find number of quadruples for which product of first and last pairs are same in Python

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

Suppose we have a list of numbers called nums, with unique positive numbers. We have to find the number of quadruples like (a, b, c, d) from nums such that a*b = c*d, where a, b, c and d are all distinct elements of nums. So, if the input is like nums = [3, 6, 4, 8], then the output will be 8, because the quadruples are [[3, 8, 6, 4], [3, 8, 4, 6], [8, 3, 6, 4], [8, 3, 4, 6], [6, 4, 3, 8], [4, 6, 3, 8], [6, 4, 8, 3], [4, 6, 8, 3]]. ...

Read More

Program to find number of operations needed to make pairs from first and last side are with same sum in Python

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

Suppose we have a list of numbers called nums with even length. We can perform operations where we select any number and update it with a value in range [1, maximum of nums]. We need to find the minimum number of operations required so that for every index i, nums[i] + nums[n-1-i] equals the same number. For example, if nums = [8, 6, 2, 5, 9, 2], we can change the first 2 at index 2 to 5, and 9 at index 4 to 4. The array becomes [8, 6, 5, 5, 4, 2], where all pairs sum to ...

Read More

Program to find number of elements can be removed to make odd and even indexed elements sum equal in Python

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

Given a list of numbers, we need to find how many elements can be removed such that the sum of even-indexed elements equals the sum of odd-indexed elements in the resulting array. This problem uses prefix sums to efficiently calculate sums after element removal. Problem Understanding For each element at index i, we simulate its removal and check if the remaining elements have equal even and odd index sums. After removing an element, all subsequent elements shift left by one position, changing their index parity. Example Given nums = [6, 8, 5, 2, 3] ? ...

Read More

Program to find stone removal rate in K hours in Python

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

Suppose we have a list of numbers called piles and a value k. The piles[i] represents the number of stones on pile i. On each hour, we select any pile and remove r number of stones from that pile. If we pick a pile with fewer than r stones, it still takes an hour to clear the pile. We have to find the minimum value of r, such that we can remove all the stones in less than or equal to k hours. So, if the input is like piles = [3, 6, 4] and k = 5, then ...

Read More

Program to find dropped correct sensor value from the faulty list in Python

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

Suppose we have two lists nums1 and nums2 representing sensor metrics. Each list contains unique values where no two elements are equal. One list holds accurate sensor metrics while the other contains faulty data. In the faulty list, one value (not the last) was dropped and a wrong value was placed at the end. We need to find the actual value that was dropped. For example, if nums1 = [5, 10, 15] and nums2 = [10, 15, 8], the output will be 5. The first list nums1 holds the actual values [5, 10, 15], while in the second array, ...

Read More

Program to count number of ways ball can drop to lowest level by avoiding blacklisted steps in Python

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

Suppose we have a value h and a list of numbers called blacklist. We are currently at height h, and are playing a game to move a small ball down to height 0. Now, in even rounds (starting from 0) we can move the ball 1, 2, or 4 stairs down. And in odd rounds, we can move the ball 1, 3, or 4 stairs down. Some levels are blacklisted. So if the ball reach there, it will die immediately. We have to find the number of ways the ball can move down at height 0. If the answer is ...

Read More

Program to count number of operations needed to make string as concatenation of same string twice in Python

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

Suppose we have a lowercase string s. We need to find the minimum number of operations (delete, insert, or update) required to make s equal to the concatenation of some string t with itself (s = t + t). So, if the input is like s = "pqrxqsr", then the output will be 2. We can update the "x" with "p" and delete "s", making s = "pqrpqr", which is t + t where t = "pqr". Algorithm We solve this by trying all possible split points and using edit distance ? For each position ...

Read More

Program to find length of smallest sublist that can be deleted to make sum divisible by k in Python

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

When working with arrays and modular arithmetic, sometimes we need to find the shortest subarray to remove so that the remaining elements' sum is divisible by a given number k. This problem uses prefix sums and hash maps to efficiently find the optimal subarray to delete. Problem Understanding Given a list of positive integers and a positive number k, we need to find the length of the shortest subarray that can be deleted to make the remaining sum divisible by k. We cannot delete the entire array. Example For nums = [5, 8, 6, 3] and ...

Read More

Program to find minimum deletions to make strings strings in Python

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

Sometimes we need to find the minimum number of deletions required to make two strings equal. This is a classic dynamic programming problem that can be solved by finding the Longest Common Subsequence (LCS) and subtracting it from the total length of both strings. Given two lowercase strings s and t, we need to delete characters from either string to make them identical. The key insight is that we want to keep the maximum number of common characters and delete the rest. Problem Example If we have s = "pipe" and t = "ripe", we can delete ...

Read More
Showing 91–100 of 3,768 articles
« Prev 1 8 9 10 11 12 377 Next »
Advertisements