Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 298 of 377

Find Surpasser Count of each element in array in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 316 Views

Suppose one array A is given. We have to find a number of surpasser of each element in that array. The surpassers are greater elements which are present at the right side of the array of the current element. Suppose A = {2, 7, 5, 3, 0, 8, 1}, the surpassers are {4, 1, 1, 1, 2, 0, 0}, so 2 has 4 numbers at right side, which are greater than 4, and the same rule for others. The solution is very simple, two nested loops will be there, for each element, it will count surpassers, then store them into ...

Read More

BFS using STL for competitive coding in C++?

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 777 Views

The Breadth First Search (BFS) traversal is an algorithm, which is used to visit all of the nodes of a given graph. In this traversal algorithm one node is selected and then all of the adjacent nodes are visited one by one. After completing all of the adjacent vertices, it moves further to check another vertices and checks its adjacent vertices again.In The competitive coding, we have to solve problems very quickly. We will use the STL (Standard Library of C++) to implement this algorithm, we need to use the Queue data structure. All the adjacent vertices are added into ...

Read More

Find the other number when LCM and HCF given in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 156 Views

Suppose we have a number A, and LCM and GCD values, we have to find another number B. If A = 5, LCM is 25, HCF = 4, then another number will be 4. We know that −$$𝐴∗𝐵=𝐿𝐶𝑀∗𝐻𝐶𝐹$$$$𝐵= \frac{LCM*HCF}{A}$$Example#include using namespace std; int anotherNumber(int A, int LCM, int GCD) {    return (LCM * GCD) / A; } int main() {    int A = 5, LCM = 25, GCD = 4;    cout

Read More

Find the resulting Colour Combination in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 386 Views

We have a string with three colors (G, B, Y). We have to find the resulting color based on these relations −B * G = YY * B = GG * Y = BSuppose the string is “GBYGB” is B. If the string is “BYB”, then it will be Y.The approach is simple; we will take the string. Compare each alphabet with adjacent characters, using the given condition, find the color.Example#include using namespace std; char combination(string s) {    char color = s[0];    for (int i = 1; i < s.length(); i++) {       if (color ...

Read More

Find two numbers whose sum and GCD are given in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 274 Views

We have the sum and gcd of two numbers a and b. We have to find both numbers a and b. If that is not possible, return -1. Suppose the sum is 6 and gcd is 2, then the numbers are 4 and 2.The approach is like, as the GCD is given, then it is known that the numbers will be multiples of it. Now there following stepsIf we choose the first number as GCD, then the second one will be sum − GCDIf the sum of the numbers is chosen in the previous step is the same as the ...

Read More

Check for integer overflow on multiplication in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 2K+ Views

Suppose we want to find the result after multiplying two numbers A and B. We have to check whether the multiplied value will exceed the 64-bit integer or not. If we multiply 100, and 200, it will not exceed, if we multiply 10000000000 and -10000000000, it will overflow.To check this, we have to follow some steps. These are like below −Steps −If anyone of the numbers is 0, then it will not exceedOtherwise, if the product of two divided by one equals to the other, then it will not exceedFor some other cases, it will exceed.Example#include #include using ...

Read More

Check if a number is magic (Recursive sum of digits is 1) in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 2K+ Views

Here we will see one program, that can check whether a number is magic number or not. A number is said to be magic number, when the recursive sum of the digits is 1. Suppose a number is like 50311 = 5 + 0 + 3 + 1 + 1 = 10 = 1 + 0 = 1, this is magic number.To check whether a number is magic or not, we have to add the digits until a single-digit number is reached.Example#include using namespace std; int isMagicNumber(int n) {    int digit_sum = 0;    while (n > 0 ...

Read More

Check if a number is sandwiched between primes in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 132 Views

Here we will see whether a number is sandwiched between primes or not. A number is said to be sandwiched between primes when the number just after it, and just below it is prime numbers. To solve this, check whether n-1 and n+1 are prime or not.Example#include #include #define N 100005 using namespace std; bool isPrime(int n) {    if (n == 0 || n == 1)       return false;    for (int i=2;i

Read More

Check if a + b = c is valid after removing all zeroes from a, b and c in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 150 Views

Suppose we have three numbers a, b, c, we have to check whether a + b = c, after removing all 0s from the numbers or not. Suppose the numbers are a = 102, b = 130, c = 2005, then after removing 0s, the numbers will be a + b = c : (12 + 13 = 25) this is trueWe will remove all 0s from a number, then we will check after removing 0s, a + b = c or not.Example#include #include using namespace std; int deleteZeros(int n) {    int res = 0;    int ...

Read More

Check if a binary string contains consecutive same or not in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 376 Views

Suppose we have a binary string. Our task is to check whether the string has consecutive same characters or not. If there are consecutive same characters, then that is invalid, otherwise valid. Then the string “101010” is valid, but “10111010” is invalid.To solve this problem, we will traverse from left to right, if two consecutive characters are the same, then return false, otherwise true.Example#include #include using namespace std; bool isConsecutiveSame(string str){    int len = str.length();    for(int i = 0; i

Read More
Showing 2971–2980 of 3,768 articles
« Prev 1 296 297 298 299 300 377 Next »
Advertisements