Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 304 of 377

Maximum Consecutive Zeroes in Concatenated Binary String in C++

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

Suppose we have a binary string of length n, another value say k is given. We have to concatenate the binary string k times. Then we have to find the maximum number of consecutive 0s in the concatenated string. Suppose binary string is “0010010”, and k = 2, then after concatenating the string k times, it will be “00100100010010”. So the maximum number of consecutive 0s is 3.The approach is simple. If the number has all 0s, then the answer will be n * k. If the string contains ones, then the result will be either the max length of ...

Read More

Maximum GCD from Given Product of Unknowns in C++

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

Suppose we two integers N and P. The P is the product of N unknown integers. We have to find the GCD of those integers. There can be different groups of integers possible, that will give the same result. Here we will produce GCD, which is maximum among all possible groups. Suppose N = 3, and P = 24, then different groups will be like {1, 1, 24}, {1, 2, 12}, {1, 3, 8}, {1, 4, 6}, {2, 2, 6}, {2, 3, 4}. The GCDs are: 1, 1, 1, 1, 2, 1. So answer is 2 here.The technique us like, ...

Read More

Check if a given directed graph is strongly connected in C++

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

Suppose we have a graph. We have to check whether the graph is strongly connected or not. A graph is said to be strongly connected, if any two vertices have a path between them, then the graph is connected. An undirected graph is strongly connected graph. Some undirected graph may be connected but not strongly connected. This is an example of a strongly connected graph.This is an example of a connected, but not strongly connected graph.Here we will see, how to check a graph is strongly connected or not using the following steps.Steps −Mark all nodes as not visitedStart DFS ...

Read More

Check if a given string is made up of two alternating characters in C++

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

Here we will see how to check a string is made up of alternating characters or not. If a string is like XYXYXY, it is valid, if a string is like ABCD, that is invalid.The approach is simple. We will check whether all ith character and i+2 th character are same or not. if they are not same, then return false, otherwise return true.Example#include using namespace std; bool hasAlternateChars(string str){    for (int i = 0; i < str.length() - 2; i++) {       if (str[i] != str[i + 2]) {          return false; ...

Read More

Check if a given string is sum-string in C++

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

Here we will see how to check whether a string is sum-string or not. A string is said to be sum-string if the rightmost substring can be written as the sum of two substrings before it, and the same is recursively true for substring before it. Suppose a string like 12243660 is a sum string, like 12 + 24 = 36, and the 36 is present after 12 and 24 in the string, again 24 + 36 = 60, this is also present in the string.A string S can be called sum-string, if it follows this rule −𝑠𝑢𝑏𝑠𝑡𝑟𝑖𝑛𝑔(𝑖, 𝑥)+𝑠𝑢𝑏𝑠𝑡𝑟𝑖𝑛𝑔(𝑥+1, 𝑗)= ...

Read More

Check if a given tree graph is linear or not in C++

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

Here we will see how to check whether a tree graph is linear or not. A linear tree graph can be expressed in one line, suppose this is an example of a linear tree graph.But this is not linear −To check a graph is linear or not, we can follow two conditionsIf the number of nodes is 1, then the tree graph is linearIf (n – 2) of its nodes have in-degree 2Example#include #include #define N 4 using namespace std; class Graph{    private:    int V;    vector *adj;    public:    Graph(int v){       ...

Read More

Check if a large number is divisibility by 15 in C++

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

Here we will see how to check a number is divisible by 15 or not. In this case the number is very large number. So we put the number as string.To check whether a number is divisible by 15, if the number is divisible by 5, and divisible by 3. So to check divisibility by 5, we have to see the last number is 0 or 5. To check divisibility by 3, we will see the sum of digits are divisible by 3 or not.Example#include using namespace std; bool isDiv15(string num){    int n = num.length();    if(num[n - ...

Read More

Check if a line touches or intersects a circle in C++

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

Suppose we have a circle and another straight line. Our task is to find if the line touches the circle or intersects it, otherwise, it passes through outside. So there are three different cases like below −Here we will solve it by following steps. These are like below −Find perpendicular P between the center and given a lineCompare P with radius r −if P > r, then outsideif P = r, then touchesotherwise insideTo get the perpendicular distance, we have to use this formula (a center point is (h, k))$$\frac{ah+bk+c}{\sqrt{a^2+b^2}}$$Example#include #include using namespace std; void isTouchOrIntersect(int a, int ...

Read More

Check if a Matrix is Invertible in C++

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

Here we will see how to check whether a matrix is invertible or not. If one matrix is M, then the inverted matrix M-1 will be −$$M^-1=\frac{adj(M)}{|M\lvert}$$So if the determinant of M is non-zero, then only we can get the inverse, otherwise, we will not get the inverse of it. So here we have to check the determinant is non-zero or not. Finding a determinant is one recursive process. We have to find submatrix, then find the determinant of it, then use that result for the final calculation. Let us see the code to get a better idea.Example#include #define ...

Read More

Check if a large number is divisible by 2, 3 and 5 or not in C++

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

Here we will see how to check a number is divisible by 2, 3 and 5 or not. In this case the number is very large number. So we put the number as string.A number will be divisible by 2, 3 and 5 if that number is divisible by LCM of 2, 3 and 5. So the LCM of 2, 3, 5 is 30. We have to check the number is divisible by 30 or not. A number is divisible by 30 when it is divisible by 10 (last digit is 0) and divisible by 3 (sum of all digits ...

Read More
Showing 3031–3040 of 3,768 articles
« Prev 1 302 303 304 305 306 377 Next »
Advertisements