Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 14 of 377

Program to find land with longest distance from water in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 242 Views

Suppose we have a binary matrix where, 0 represents water and 1 represents land. Now we have to find the land which has the longest Manhattan distance from water and finally return the distance.So, if the input is like1111110111110011then the output will be 3, as [0, 0] cell has Manhattan distance of 3 from water.To solve this, we will follow these steps −if A is empty, thenreturn 0R := row count of matrix, C := column count of matrixdistance := a matrix of order R x C and fill with 0q := a double ended queue with some pairs (r, ...

Read More

Program to find minimum number colors remain after merging in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 247 Views

Suppose we have a list of colors (R, G, B). Now if two different colors are there next to each other then they can transform into a single color item of the third color. We have to find the smallest number of them remaining after any possible sequence of such transformations.So, if the input is like colors = ["G", "R", "G", "B", "R"], then the output will be 1 as it can transform like below −To solve this, we will follow these steps −n := size of colorsif colors has only one distinct color, thenreturn nif n

Read More

Check if a number can be expressed as a^b in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 396 Views

Suppose we have a number n. We have to check whether we can make express it like a^b or not.So, if the input is like 125, then the output will be True as 125 = 5^3, so a = 5 and b = 3To solve this, we will follow these steps −if num is same as 1, then:return truefor initialize i := 2, when i * i

Read More

Program to check we can cross river by stones or not in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 411 Views

Suppose we have a list of sorted numbers called stones and this is representing the positions of stones on a river that we are trying to cross. To cross the river, we must finish at the last stone. Now in each step, we can jump (k - 1, k, or k + 1) steps ahead where k is the distance of the last jump. We have to check whether we can cross the river or not.So, if the input is like stones = [0, 1, 3, 4, 5, 6, 8, 9, 13], then the output will be True, as we ...

Read More

Check whether second string can be formed from characters of first string in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 534 Views

Suppose we have two strings s and t. We have to check whether t can be formed using characters of s or not.So, if the input is like s = "owleh" t = "hello", then the output will be True.To solve this, we will follow these steps −freq := a map containing all characters and their frequenciesfor i in range 0 to size of t - 1, doif freq[t[i]] is 0, thenreturn Falsefreq[t[i]] := freq[t[i]] - 1return TrueLet us see the following implementation to get better understanding −Example Codefrom collections import defaultdict   def solve(s, t):    freq = defaultdict(int) ...

Read More

Program to check whether first player can win a game where players can form string char by char in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 234 Views

Suppose we have a list of words. Now consider a ghost game where two players can participate into it. Here players alternate appending letters to a string. And the string that is being made must be a valid prefix of a word in the list, and the player who spells out any word in the list loses. We have to check whether the first player can win or not if both players are playing optimally.So, if the input is like words = ["manage", "manager", "min"], then the output will be True, as they can play like −m [Player 1]ma [Player ...

Read More

Check whether sum of digits at odd places of a number is divisible by K in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 169 Views

Suppose we have a number n and another number k, we have to check whether the sum of digits of n at it's odd places (from right side to left side) is divisible by k or not.So, if the input is like n = 2416 k = 5, then the output will be True as sum of odd placed numbers from right to left is 4 + 6 = 10. Which is divisible by 5.To solve this, we will follow these steps −total := 0, pos := 1while n > 0 , doif pos is odd, thentotal := total + ...

Read More

Program to count number of queries that are true in a graph with weighted path in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 157 Views

Suppose we have an edge list for an undirected graph where each edge has [u, v, w] fields, u and v are source and destination vertices and w is the weight. And also have a list of queries of the same form [u, v, w]. That represents the question of does there exist a path between u and v such that each edge in the path have weight of at most w. So find the number of queries that are true.So, if the input is like edges = [[0, 1, 6], [1, 2, 7], [2, 3, 8], [0, 3, 5]] ...

Read More

Check whether the Average Character of the String is present or not in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 157 Views

Suppose we have a string s that contains alphanumeric characters, we have to check whether the average character of the string is present or not, if yes then return that character. Here the average character can be found by taking floor of average of each character ASCII values in s.So, if the input is like s = “pqrst”, then the output will be 'r' because the average of character ASCII values are (112 + 113 + 114 + 115 + 116)/5 = 570/5 = 114 (r).To solve this, we will follow these steps −total := 0for each ch in s, ...

Read More

Program to find minimum number of pins required to hang all banners in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 350 Views

Suppose we have a list of intervals of the form [start, end] this is representing the starts and end points of banners we want to hang. At least one pin is required to hang a banner, and one pin can hang more than once banners. We have to find the smallest number of pins required to hang all the banners.So, if the input is like intervals = [[2, 5], [5, 6], [8, 10], [10, 13]], then the output will be 2, as we can put two pins at position 5 and 10 to hang all of the banners.To solve this, ...

Read More
Showing 131–140 of 3,768 articles
« Prev 1 12 13 14 15 16 377 Next »
Advertisements