Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 30 of 377

C++ code to find out who won an n-round game

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2022 467 Views

Suppose, there is a two-player game that has n rounds. The scores of the rounds are given in an array 'scores' where each element is of the format {P1 Score, P2 Score}. The player with the higher score wins a round, and a player wins the game if they have won more rounds; otherwise, it is declared as a draw. So, given the scores, we have to find out who has won the game.So, if the input is like n = 4, scores = {{4, 3}, {3, 2}, {5, 6}, {2, 5}}, then the output will be Draw.StepsTo solve this, ...

Read More

C++ code to find out number of battery combos

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2022 405 Views

Suppose, we have n batteries that can be used a maximum of 5 times. We have some devices that need three batteries and each usage of the device increases the usage count of the batteries by 1. If we have to use the devices k times, we have to find out how many battery combinations we can make to power the devices. A battery cannot be used in two devices simultaneously and a battery that has been used 5 times cannot be included. The usage count of the batteries is given in the array batt.So, if the input is like ...

Read More

C++ program to find winner of ball removal game

Arnab Chakraborty
Arnab Chakraborty
Updated on 04-Mar-2022 336 Views

Suppose we have four numbers n1, n2, k1 and k2. Consider there are 2 boxes, first one has n1 balls and second one has n2 balls. Amal and Bimal are playing the game. In one move they can take from 1 to k1 balls and throw them out, similarly second one will take 1 to k2 balls in his move. Amal starts the game and they plays alternatively. The one who cannot play his move will lose the game. We have to find who will be the winner.So, if the input is like n1 = 2; n2 = 2; k1 ...

Read More

C++ program to find minimum how much rupees we have to pay to buy exactly n liters of water

Arnab Chakraborty
Arnab Chakraborty
Updated on 04-Mar-2022 253 Views

Suppose we have three numbers n, a and b. We want to buy n liters of water. There are only two types of water bottles nearby, 1-liter bottles and 2-liter bottles. The bottle of the first type a rupees and the bottle of the second type costs b rupees. We want to spend as few money as possible. We have to find the minimum amount of money we need to buy exactly n liters of water.So, if the input is like n = 7; a = 3; b = 2, then the output will be 9, because with 3 2-liter ...

Read More

C++ Program to find minimum possible ugliness we can achieve of towers

Arnab Chakraborty
Arnab Chakraborty
Updated on 04-Mar-2022 220 Views

Suppose we have an array A with n elements. Consider there are n block towers in a row. The ith tower has height A[i]. In a single day, we can perform the operation: Select two indices i and j (i != j) and move back from tower i to j. It will decrease A[i] by 1 and increase A[j] by 1. The ugliness of the buildings is max(A) − min(A). We have to find the minimum possible ugliness we can achieve.So, if the input is like A = [1, 2, 3, 1, 5], then the output will be 1, because ...

Read More

C++ Program to find room status after checking guest appearance record

Arnab Chakraborty
Arnab Chakraborty
Updated on 04-Mar-2022 373 Views

Suppose we have a string S with 'L', 'R' and digits from 0 to 9. Consider there is a hotel with 10 rooms they are numbered from 0 to 9, from left to right. The hotel has two entrances-one from the left side, and another from the right side. When a customer arrives to the hotel through the left entrance, they get an empty room closest to the left entrance. Similarly, when a customer arrives at the hotel through the right entrance, they get an empty room closest to the right entrance. But we have lost the room assignment list. ...

Read More

C++ Program to find winner name of stick crossing game

Arnab Chakraborty
Arnab Chakraborty
Updated on 04-Mar-2022 298 Views

Suppose we have two numbers n and k. Amal and Bimal are playing a game. The rules are simple. Amal draws n sticks in a row. After that the players take turns crossing out exactly k sticks from left or right in each turn. Amal starts the game. If there are less than k sticks on the paper before some turn, the game ends. Amal wins if he makes strictly more moves than Bimal. We have to find who will be the winner.So, if the input is like n = 10; k = 4, then the output will be Bimal. ...

Read More

C++ Program to count number of operations needed to place elements whose index is smaller than value

Arnab Chakraborty
Arnab Chakraborty
Updated on 04-Mar-2022 311 Views

Suppose we have an array A with n elements. We can perform these operations any number of times −Select any positive integer kSelect any position in the sequence and insert k into that positionSo, the sequence is changed, we proceed with this sequence in the next operation.We have to find minimum number of operations needed to satisfy the condition: A[i]

Read More

C++ program to find length of non empty substring whose sum is even

Arnab Chakraborty
Arnab Chakraborty
Updated on 04-Mar-2022 168 Views

Suppose we have an array A with n elements. We have to find the length of a non-empty subset of its elements such that their sum is even or return -1 when there is no such subset.So, if the input is like A = [1, 3, 7], then the output will be 2, because sum of [1, 3] is 4.StepsTo solve this, we will follow these steps −n := size of A for initialize i := 0, when i < n, update (increase i by 1), do:    if A[i] mod 2 is same as 0, then:       ...

Read More

C++ program to find string with palindrome substring whose length is at most k

Arnab Chakraborty
Arnab Chakraborty
Updated on 04-Mar-2022 330 Views

Suppose we have two numbers n and k. Let we are trying to generate a string S with only three types of characters 'a', 'b' and 'c'. The maximum length of a substring of the string S that is a palindrome which does not exceeds k.So, if the input is like n = 3; k = 2, then the output will be "aab", because its length is 3 and the palindrome substring is "aa" with length at least 2. (other answers are also possible).StepsTo solve this, we will follow these steps −S := a blank string j := 0 for ...

Read More
Showing 291–300 of 3,768 articles
« Prev 1 28 29 30 31 32 377 Next »
Advertisements