Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 243 of 377

Number of Atoms in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 08-Jun-2020 600 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

Total Hamming Distance in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 05-Jun-2020 875 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

Minimum Genetic Mutation in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 05-Jun-2020 367 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

Profitable Schemes in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 04-Jun-2020 264 Views

Suppose there is a gang with G people and a list of various crimes they could commit. The i-th crime generates a profit value profit[i] and requires group[i] gang members to participate.If a gang member is participating in one crime, that he can't participate in another crime. Now let us define profitable scheme any subset of these crimes that generates at least P profit, and total number of members participating in that subset of crimes is at most G.We have to find how many schemes can be chosen? The answer may be very large, So return it modulo 10^9 + ...

Read More

Maximum Score Words Formed by Letters in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 04-Jun-2020 303 Views

Suppose we have a list of words, a list of single letters and score for every character. We have to find the maximum score of any valid set of words formed by using the given letters.We may not use all characters in letters and each letter can only be used once. Score of letters 'a', 'b', 'c', ... ,'z' is given by score[0], score[1], ... , score[25] respectively.So, if the input is like words = ["god", "good", "toc", "cat"], letters = [a, g, o, o, d, d, d, c, t, t] and score = [5, 0, 8, 3, 0, 0, ...

Read More

Check If It Is a Good Array in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 04-Jun-2020 2K+ Views

Suppose we have an array called nums of positive integers. We have to select some subset of nums, then multiply each element by an integer and add all these numbers. The array will be a good array if we can get a sum of 1 from the array by any possible subset and multiplicand.We have to check whether the array is good or not.So, if the input is like [12, 23, 7, 5], then the output will be True, this is because If we take numbers 5, 7, then 5*3 + 7*(-2) = 1To solve this, we will follow these ...

Read More

Tiling a Rectangle with the Fewest Squares in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 04-Jun-2020 363 Views

Suppose we have a rectangle of size n x m. We have to find the minimum number of integers sided square objects that can tile the rectangles.So, if the input is like n = 2 and m = 3,then the output will be 3, as we need three blocks.To solve this, we will follow these steps −Define one map mres := infDefine a function dfs(), this will take n, m, an array h, cnt,if cnt >= res, then −returnisFull := truepos := -1, minH := inffor initialize i := 1, when i

Read More

Maximum Profit in Job Scheduling in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 04-Jun-2020 1K+ Views

Suppose we have n different tasks, where every task is scheduled to be done from startTime[i] to endTime[i], for that task we algo get profit of profit[i]. We know the startTime , endTime and profit lists, we have to find the maximum profit we can take such that there are no 2 tasks in the subset with overlapping time range. If we choose a task that ends at time X we will be able to start another task that starts at time X.So, if the input is like startTime = [1, 2, 3, 3], endTime = [3, 4, 5, 6] ...

Read More

Maximum Equal Frequency in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 04-Jun-2020 304 Views

Suppose we have an array nums of positive integers, we have to return the longest possible length of an array prefix of given array nums, such that it is possible to delete exactly one element from this prefix so that every number that has appeared in it will have the same frequency. After removing one element if there are no remaining elements, it's still considered that every appeared number has the same frequency (0).So, if the input is like [3, 3, 2, 2, 6, 4, 4, 6], then the output will be 7, So if we remove element 6 from ...

Read More

Count Vowels Permutation in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 04-Jun-2020 329 Views

Suppose we have one number n, we have to count how many strings of length n can be formed using these rules − Each character is a lower case vowel Each vowel 'a' may only be followed by an 'e'. Each vowel 'e' may only be followed by an 'a' or 'i'. Each vowel 'i' may not be followed by another 'i'. Each vowel 'o' may only be followed by an 'i' or 'u'. Each vowel 'u' may only be followed by an 'a'. The answer may be too large, so we will find the answer modulo 10^9 + 7.So, ...

Read More
Showing 2421–2430 of 3,768 articles
« Prev 1 241 242 243 244 245 377 Next »
Advertisements