Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 33 of 377

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 283 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 362 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 364 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

C++ program to find order of loading golds on weight scale without exploding it

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

Suppose we have an array A with n distinct elements, and another number x. There are n pieces of gold. The ith gold weight is A[i]. We will put this n pieces on weight scale one piece at a time. But the scale has an unusual defect: if the total weight on it is exactly x, it will explode. We have to check whether we can put all n gold pieces onto the scale in some order, without exploding the scale during the process. If we can, find that order. If not possible, mark "IMPOSSIBLE".So, if the input is like ...

Read More

C++ program to check xor game results 0 or not

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

Suppose we have an array A with N elements and another binary string S. Consider two players are playing a game. They are numbered as 0 and 1. There is one variable x whose initial value is 0. The games has N rounds. In ith round person S[i] does one of the following: replace x with x XOR A[i], otherwise do nothing. Person 0 wants 0 at the end of this game but person 1 wants non-zero. We have to check whether x becomes 0 at the end or not.So, if the input is like A = [1, 2]; S ...

Read More

C++ program to concatenate strings in reverse order

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

Suppose we have two strings S and T. Both are in lowercase letters. Concatenate T and S in this order to generate the final string.So, if the input is like S = "ramming"; T = "prog", then the output will be "programming"StepsTo solve this, we will follow these steps −res := T concatenate S return resExampleLet us see the following implementation to get better understanding −#include using namespace std; string solve(string S, string T){    string res = T + S;    return res; } int main(){    string S = "ramming";    string T = "prog";    cout

Read More

C++ program to count number of cities we can visit from each city with given operations

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

Suppose we have a list of N coordinate points P in the form (xi, yi). The x and y values are permutation of first N natural numbers. For each k in range 1 to N. We are at city k. We can apply the operations arbitrarily many times. The operation: We move to another city that has a smaller x-coordinate and a smaller y-coordinate or larger x or larger y coordinate than the city we are currently in. We have to find the number of cities we can reach from city k.So, if the input is like P = [[1, ...

Read More

C++ program to count number of operations needed to reach n by paying coins

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

Suppose we have five numbers, N, A, B, C, D. We start with a number 0 and end at N. We can change a number by certain number of coins with the following operations −Multiply the number by 2, paying A coinsMultiply the number by 3, paying B coinsMultiply the number by 5, paying C coinsIncrease or decrease the number by 1, paying D coins.We can perform these operations any number of times in any order. We have to find the minimum number of coins we need to reach NSo, if the input is like N = 11; A = ...

Read More

C++ program to find maximum distance between two rival students after x swaps

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

Suppose we have four numbers n, x, a and b. There are n students in the row. There are two rivalling students among them. One of them is at position a and another one is at position b. Positions are numbered from 1 to n from left to right. We want to maximize the distance between these two students. We can perform the following operation x times: Select two adjacent students and then swap them. We have to find the maximum possible distance after x swaps.So, if the input is like n = 5; x = 1; a = 3; ...

Read More

C++ program to find array after removal of left occurrences of duplicate elements

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

Suppose we have an array A with n elements. We want to remove duplicate elements. We want to leave only the rightmost entry for each element of the array. The relative order of the remaining unique elements should not be changed.So, if the input is like A = [1, 5, 5, 1, 6, 1], then the output will be [5, 6, 1]StepsTo solve this, we will follow these steps −Define two arrays b and vis of size: 1200 each x := 0 n := size of A for initialize i := n - 1, when i >= 0, update (decrease ...

Read More
Showing 321–330 of 3,768 articles
« Prev 1 31 32 33 34 35 377 Next »
Advertisements