Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 262 of 377

C++ program to find minimum how many coins needed to buy binary string

Arnab Chakraborty
Arnab Chakraborty
Updated on 03-Mar-2022 238 Views

Suppose we have three numbers c0, c1 and h, and a binary string S. We can flip any bit in S. We should pay h coins for each change. After some changes (possibly zero) we want to buy the string. To buy the string we should buy all its characters. To buy the bit 0 we should pay c0 coins, to buy the bit 1 you should pay c1 coins. We have to find the minimum number of coins needed to buy the string.So, if the input is like c0 = 10; c1 = 100; h = 1; S = ...

Read More

C++ program to count how many ways two players win or make draw in dice throwing game

Arnab Chakraborty
Arnab Chakraborty
Updated on 03-Mar-2022 292 Views

Suppose we have two numbers a and b. Amal and Bimal are playing a game. First each of them writes an integer from 1 to 6, then a dice is thrown. The player whose written number got closer to the number written on the paper, he wins that round, if both of them has the same difference, then that is a draw. If Amal writes the number a, and Bimal writes b, then we have to count the number of possible ways the Amal will win, number of possible draw and number of ways Bimal can win.So, if the input ...

Read More

C++ program to count minimum number of binary digit numbers needed to represent n

Arnab Chakraborty
Arnab Chakraborty
Updated on 03-Mar-2022 401 Views

Suppose we have a number n. A number is a binary decimal if it's a positive integer and all digits in its decimal notation are either 0 or 1. For example, 1001 (one thousand and one) is a binary decimal, while 1021 are not. From the number n, we have to represent n as a sum of some (not necessarily distinct) binary decimals. Then compute the smallest number of binary decimals required for that.So, if the input is like n = 121, then the output will be 2, because this can be represented as 110 + 11 or 111 + ...

Read More

C++ program to find sequence of indices of the team members

Arnab Chakraborty
Arnab Chakraborty
Updated on 03-Mar-2022 246 Views

Suppose we have an array A with n elements and a number k. There are n students in a class. The rating of ith student is A[i]. We have to form a team with k students such that rating of all team members are distinct. If not possible return "Impossible", otherwise return the sequence of indices.So, if the input is like A = [15, 13, 15, 15, 12]; k = 3, then the output will be [1, 2, 5].StepsTo solve this, we will follow these steps −Define two large arrays app and ans and fill them with cnt := 0 ...

Read More

C++ program to find reduced size of the array after removal operations

Arnab Chakraborty
Arnab Chakraborty
Updated on 03-Mar-2022 226 Views

Suppose we have an array A with n elements. Consider there is a password with n positive integers. We apply the following operations on the array. The operations is to remove two adjacent elements that are not same as each other, then put their sum at that location. So this operation will reduce the size of array by 1. We have to find the shortest possible length of the array after performing these operations.So, if the input is like A = [2, 1, 3, 1], then the output will be 1, because if we select (1, 3), the array will ...

Read More

C++ program to find array after inserting new elements where any two elements difference is in array

Arnab Chakraborty
Arnab Chakraborty
Updated on 03-Mar-2022 204 Views

Suppose we have an array A with n distinct elements. An array B is called nice if for any two distinct elements B[i] and B[j], the |B[i] - B[j]| appears in B at least once, and all elements in B will be distinct. We have to check whether we can add several integers in A to make it nice of size at most 300. If possible return the new array, otherwise return -1.So, if the input is like A = [4, 8, 12, 6], then the output will be [8, 12, 6, 2, 4, 10], because |4−2| = |6−4| = ...

Read More

C++ program to check whether given string is bad or not

Arnab Chakraborty
Arnab Chakraborty
Updated on 03-Mar-2022 381 Views

Suppose we have a string S with n characters. S contains lowercase English letters and ')' characters. The string is bad, if the number of characters ')' at the end is strictly greater than the number of remaining characters. We have to check whether S is bad or not.So, if the input is like S = "fega))))))", then the output will be True, because this is bad as there are 4 letters and 6 ')'s.StepsTo solve this, we will follow these steps −ans := 0 n := size of S i := n - 1 while (i >= 0 and ...

Read More

C++ program to find minimum difference between the sums of two subsets from first n natural numbers

Arnab Chakraborty
Arnab Chakraborty
Updated on 03-Mar-2022 286 Views

Suppose we have a number n. Consider, first n natural numbers. We have to split them into two sets A and B such that each element belongs to exactly one set and the absolute difference between the sum of elements in A and sum of elements in B is minimum, and find that difference.So, if the input is like n = 5, then the output will be 1, because if we make A = {1, 3, 4} and B = {2, 5}, then the sum values are 8 and 7, so difference is 1.StepsTo solve this, we will follow these ...

Read More

C++ program to count number of stairways and number of steps in each stairways

Arnab Chakraborty
Arnab Chakraborty
Updated on 03-Mar-2022 366 Views

Suppose we have an array A with n elements. Let, Amal climbs the stairs inside a multi-storey building. Every time he climbs, start counting from 1. For example, if he climbs two stairways with 3 steps and 4 steps, he will speak the numbers like 1, 2, 3, 1, 2, 3, 4. In the array A, the numbers are representing stair numbers said by Amal. We have to count the number of staircase did he climb, also print the number of steps in each stairway.So, if the input is like A = [1, 2, 3, 1, 2, 3, 4, 5], ...

Read More

C++ program to find indices of soldiers who can form reconnaissance unit

Arnab Chakraborty
Arnab Chakraborty
Updated on 03-Mar-2022 365 Views

Suppose we have an array A with n elements. There are n soldiers standing on a circle. For ith soldier, the height is A[i]. A reconnaissance unit can be made of such two adjacent soldiers, whose heights difference is minimal. So each of them will be less noticeable with the other. We have to find the indices of the pair of soldiers that can form a reconnaissance unit.So, if the input is like A = [10, 12, 13, 15, 10], then the output will be (5, 1).StepsTo solve this, we will follow these steps −n := size of A D ...

Read More
Showing 2611–2620 of 3,768 articles
« Prev 1 260 261 262 263 264 377 Next »
Advertisements