Arnab Chakraborty has Published 4452 Articles

Program to count number of swaps required to group all 1s together in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 12-Dec-2020 09:37:51

97 Views

Suppose we have a binary string, and we can swap any two bits. We have to find the minimum number of swaps required to group all 1s together.So, if the input is like s = "0111001", then the output will be 1, as We can perform these swaps: 0111001 -> ... 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 12-Dec-2020 09:35:09

54 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 ... 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 12-Dec-2020 09:32:10

126 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 ... Read More

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

Arnab Chakraborty

Arnab Chakraborty

Updated on 12-Dec-2020 09:29:42

265 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 ... Read More

Program to find minimum number colors remain after merging in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 12-Dec-2020 09:27:21

128 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 ... Read More

Program to find land with longest distance from water in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 12-Dec-2020 09:25:00

119 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 ... Read More

Program to get operations to convert one string to another in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 12-Dec-2020 09:22:27

147 Views

Suppose we have two strings S and T. We have to find the shortest sequence of operations that changes S to T. Here the operations are basically either deleting or inserting a character.So, if the input is like S = "xxxy" T = "xxyy", then the output will be ["x", ... Read More

Program to count number of ways we can fill 3 x n box with 2 x 1 dominos in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 12-Dec-2020 09:18:55

146 Views

Suppose we have a number n, we have to find the number of ways we can fill a (3 x n) block with 1 x 2 dominos. We can rotate the dominos when required. If the answer is very large then return this mod 10^9 + 7.So, if the input ... Read More

Program to find nth term of a sequence which are divisible by a, b, c in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 12-Dec-2020 09:17:05

271 Views

Suppose we have four numbers n, a, b, and c. We have to find the nth (0 indexed) term of the sorted sequence of numbers divisible by a, b or c.So, if the input is like n = 8 a = 3 b = 7 c = 9, then the ... Read More

Program to find length of the largest subset where one element in every pair is divisible by other in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 12-Dec-2020 09:13:56

261 Views

Suppose we have a list of unique numbers called nums, so we have to find the largest subset such that every pair of elements in the subset like (i, j) satisfies either i % j = 0 or j % i = 0. So we have to find the size ... Read More

Advertisements