Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 257 of 377

C++ code to find final number after min max removal game

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2022 301 Views

Suppose we have an array A with n elements. There are n numbers written on a board. Amal and Bimal are playing a turn based game. In each turn, they select a number and remove it from board. Amal plays first. Amal wants to minimize the last number that he would left on the board, and Bimal wants to maximize it. We have to find the number which will remain on the board.So, if the input is like A = [2, 1, 3], then the output will be 2, because Amal will remove 3, Bimal will remove 1, so the ...

Read More

C++ code to find how many upgrade to make HP greater than current

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2022 384 Views

Suppose we have a number n. In a game, every character has four different health points (HP). The categories are as follows −Category A : If HP is in the form (4n + 1)Category B : If HP is in the form (4n + 3)Category C : If HP is in the form (4n + 2)Category D : If HP is in the form 4nThese 4 categories ordered from highest to lowest as A > B > C > D. So, category A is the highest and category D is the lowest. While playing the game, players can increase the ...

Read More

C++ code to check we flew to Florida more than Seattle

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2022 114 Views

Suppose we have a string S with two kinds of letters 'S' and 'F'. If S[i] is 'S' we are at Seattle on ith day, and if it is 'F' we are at Florida. We have to check whether we flew more times from Seattle to Florida than Florida to Seattle.So, if the input is like S = "SSFFSFFSFF", then the output will be True.StepsTo solve this, we will follow these steps −n := size of S if S[0] is same as 'S' and S[n - 1] is same as 'F', then:    return true Otherwise    return falseExampleLet us ...

Read More

C++ code to find pair of numbers where one is multiple of other

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2022 395 Views

Suppose we have two numbers l and r. We have to find such pair (x, y), such that l

Read More

C++ code to count number of dice rolls to get target x

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2022 317 Views

Suppose we have a number x. We have a six-faced dice and its faces are numbered from 2 to 7. We want exactly x points from the dice. When we throw the dice the face number will be added up to reach our target. We do not really care about the number of dice rolls, so we just want to know any number of rolls we can make to be able to get exactly x points for them. We are very lucky, so if the probability to get x points with chosen number of rolls is non-zero, we will be ...

Read More

C++ code to check string is diverse or not

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2022 367 Views

Suppose we have a string S with n lowercase letters. A string is called diverse if it has consecutive letters of the English alphabet and each letter occurs exactly once. (letters 'a' and 'z' are not adjacent). We have to check whether it is diverse or not.So, if the input is like S = "fced", then the output will be True.StepsTo solve this, we will follow these steps −sort the array S flag := 1 for initialize i := 1, when i < size of S and flag is non-zero, update (increase i by 1), do:    if S[i] - ...

Read More

C++ code to find max ornaments to make decoration good

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2022 335 Views

Suppose we have three numbers y, b and r. There are y yellow ornaments, b blue ornaments and r red ornaments for decoration. A decoration will be beautiful, if the number of blue ornaments used is greater by exactly 1 than the number of yellow ornaments, and the number of red ornaments used is greater by exactly 1 than the number of blue ornaments. We want to choose as many ornaments as possible and also want to make our decoration good. We have to find the maximum number of ornaments used for a beautiful decoration.So, if the input is like ...

Read More

C++ code to find rank of student from score table

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2022 1K+ Views

Suppose we have a 2d array of size n x 4. Consider there are n students and their ids are starting from 0 to n-1. Each of them has four scores on English, Geography, Maths and History. In the table, the students will be sorted by decreasing the sum of their scores. If two or more students have the same sum, these students will be sorted by increasing their ids. We have to find the id of student whose id is 0.So, if the input is like10098100100100100100100909990100100986099then the output will be 2StepsTo solve this, we will follow these steps −n ...

Read More

C++ code to find minimum moves with weapons to kill enemy

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2022 809 Views

Suppose we have an array A with n elements, and another number H. H is health of an enemy. We have n weapons and damaging power of ith weapon is A[i]. Different weapons can be used to kill the enemy. We cannot use same weapon twice in a row. We have to count minimum how many times we can use weapons to kill the enemy.So, if the input is like A = [2, 1, 7]; H = 11, then the output will be 3, because if we use weapon with damage power 7, then use 2 then again use 7 ...

Read More

C++ code to get updated string with same &#039;a&#039; and &#039;b&#039; count

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2022 229 Views

Suppose we have as string S with even length n. S contains only two types of characters 'a' and 'b'. We want to modify the string so that every its prefix of its length has an equal amount of letters 'a' and 'b'. To achieve that, we can perform the following operation arbitrary number of times: Select some position in his string and replace the letter on this position with the other letter. Return the updated string.So, if the input is like S = "aabbbb", then the output will be "baabab"StepsTo solve this, we will follow these steps −n := ...

Read More
Showing 2561–2570 of 3,768 articles
« Prev 1 255 256 257 258 259 377 Next »
Advertisements