Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 237 of 377

Set Mismatch in C++

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

Suppose there is a set S that is originally containing numbers from 1 to n. But unfortunately, due to some error, one of the numbers in the set got duplicated to another number in the set, which results in repetition of one number and loss of another number.Now if we have an array called nums that is representing the data status of this set after the error. Our task is to find the number occurs twice and then find the number that is missed. return the results in the form of an array.So, if the input is like [1, 2, ...

Read More

Minimum Genetic Mutation in C++

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

Suppose we have a gene string. That can be represented by a string whose length is 8, This string is consists of these letters [A, C, G, T]. Now consider we want to investigate about a mutation, where ONE mutation is actually ONE single character changed in the gene string. As an example, "AACCGTTT" is changed like "AACCGTTA" is 1 mutation.We also have a given gene "bank", where all the valid gene mutations are present. A gene must be in the bank to make it a valid gene string.Now suppose we have given 3 things - start, end, bank, our ...

Read More

Total Hamming Distance in C++

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

Suppose we have a list of numbers. We have to find the Hamming distance of all pair of given numbers. We know that the Hamming distance between two integers is the number of positions at which the corresponding bits are different.So, if the input is like [4, 14, 17, 2], then the output will be 17.To solve this, we will follow these steps −m := 1^9 + 7Define a function add(), this will take a, b, return ((a mod m) + (b mod m))Define a function mul(), this will take a, b, return ((a mod m) * (b mod m))Define ...

Read More

Robot Return to Origin in C++

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

Suppose there is a robot and its starting position is (0, 0). If we have a sequence of its movements, we have to check whether this robot ends up at (0, 0) after it completes its moves.The move sequence is given as a string, and the character moves[i] represents its ith move. Symbols are R for right, L for left, U for up, and D for down. If the robot returns to the origin after it finishes all of its moves, return true. Otherwise, return false.So, if the input is like "RRULLD", then the output will be true, Right two-unit, ...

Read More

Image Smoother in C++

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

Suppose we have a 2D matrix M representing the gray scale of an image, we have to design a smoother to make the gray scale of each pixel becomes the average gray scale (rounding down) of all the 8 surrounding pixels and itself. If a cell has less than 8 surrounding cells, convert all possible pixels.So, if the input is like111101111then the output will be000000000To solve this, we will follow these steps −R := row count of MC := column count ofDefine an array d = { -1, 0, 1 }Define one 2D array res of size (R x C)for ...

Read More

Minimum Time Difference in C++

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

Suppose we have a list of 24-hour clock time points in "Hour:Minutes" format, we have to find the minimum minutes difference between any two time points in the list. So if the input is like [“12:30”, ”15:17”], so this will return 167.To solve this, we will follow these steps −Define an array called ok of size 24*60 + 1, and initially all are false.n := size of tpfor i in range 0 to n – 1hr := the hour part from the timemin := minute part of the stringtime := hr * 60 + minif ok[time] is true, then return ...

Read More

Number of Atoms in C++

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

Suppose we have a chemical formula; we have to find the count of each atom.An atomic element will always start with an uppercase character, there can be zero or more lowercase letters, representing the name. And 1 or more digits representing the count of that element may follow if the count is greater than 1. But if the count is 1, no digits will follow. As an example, H2O and H2O2 both are valid, but H1O2 is invalid.So, if the input is like Na2(CO)3, then the output will be C3Na2O3, so this indicates 3 Carbon (C), 2 Sodium (Na), 3 ...

Read More

Optimal Division in C++

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

Suppose we have a list of positive integers; the adjacent integers will perform the float division. So for example, [2, 3, 4] -> 2 / 3 / 4. Now, we can add any number of parenthesis at any position to change the priority of these operations. We should find out how to add parenthesis to get the maximum result, we have to find the corresponding expression in string format. Our expression should NOT contain redundant parenthesis. So if the input is like [1000, 100, 10, 2], then the result will be “1000/(100/10/2)”.To solve this, we will follow these steps −n ...

Read More

Special Binary String in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 2K+ Views

Suppose we have a spatial binary string. This string has following few properties −There are same number of 0s and 1sEvery Prefix in the binary string has at least as many 1s as 0sNow suppose we have special string S, a move is actually choosing two consecutive, non-empty, special substrings of S, and swapping them.We have to find the lexicographically largest resulting string possible, at the end of any number of moves.So, if the input is like 11011000, then the output will be 11100100, this is because: The substrings "10" and "1100" are swapped. This is the lexicographically largest string ...

Read More

Couples Holding Hands in C++

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

Suppose there are N couples and they have sat on 2N seats arranged in a row and want to hold hands. We have to find the minimum number of swaps so that every couple is sitting side by side.The people and seats are represented by a number from 0 to 2N-1, the couples are numbered in order, this is like the first couple as (0, 1), the second couple as (2, 3), and so on and the last couple as (2N-2, 2N-1).The couples' initial seating is given by another array called row, and row[i] being the value of the person ...

Read More
Showing 2361–2370 of 3,768 articles
« Prev 1 235 236 237 238 239 377 Next »
Advertisements