Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 372 of 377

Finding a Non Transitive Coprime Triplet in a Range in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 21-Oct-2019 180 Views

Suppose we have the lower and upper bound, and we have to find nontransitive triplet (x, y, z), such that the pair (x, y) are coprime (GCD is 1), the pair (y, z) are coprime, but pair (x, z) is not a coprime pair. For example, if the lower bound is 2, and upper bound is 10, then the elements are {2, 3, 4, 5, 6, 7, 8, 9, 10}, here possible triplet is (4, 7, 8), here (4, 7), and (7, 8) are coprime, but (4, 8) is not a coprime pair.We will follow the naïve approach to solve ...

Read More

Minimize ASCII values sum after removing all occurrences of one character in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 21-Oct-2019 200 Views

Suppose we have a string. We have to minimize the sum of ASCII values, of each character to the string, after removing every occurrence of a particular character. Suppose a string is given like “hello” the sum of ASCII characters is (104 + 101 + 108 + 108 + 111) = 532. Now check occurrences of each characters.h has occurred one time, so cost is 1 * 104 = 104e has occurred one time, so cost is 1 * 101 = 101l has occurred one time, so cost is 2 * 108 = 216o has occurred one time, so cost ...

Read More

Maximum Possible Edge Disjoint Spanning Tree From a Complete Graph in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 21-Oct-2019 286 Views

Suppose we have a complete graph; we have to count number of Edge Disjoint Spanning trees. The Edge Disjoint Spanning trees are spanning trees, where no two trees in the set have an edge in common. Suppose the N (number of vertices) is 4, then output will be 2. The complete graph using 4 vertices is like below −Two edge disjoint spanning trees are like −The maximum number of edge disjoint spanning tree from a complete graph, with N vertices will be $[\frac{n}{2}]$Example#include #include using namespace std; int maxEdgeDisjointSpanningTree(int n){    return floor(n/2); } int main() {    int n = 4;    cout

Read More

Check if a number is formed by Concatenation of 1, 14 or 144 only in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 21-Oct-2019 269 Views

Here we will see one problem, that can tell that whether a string or a number is a concatenation of 1, 14 or 144 only. Suppose a string is “111411441”, this is valid, but “144414” is not valid.The task is simple, we have to fetch a single digit, double-digit and triple-digit number from the last, and check whether they match with any of these three (1, 14 and 144), if we get one match, divide the number with it, and repeat this process until the entire number is not exhausted.Example#include #include using namespace std; bool checkNumber(long long number) ...

Read More

Check if a number can be expressed as sum two abundant numbers in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 21-Oct-2019 217 Views

Suppose we have a number. We have to express this as sum of two Abundant number, if yes, print the numbers, otherwise print -1. A number is said to be Abundant number is sum of all proper divisor of the number, denoted by sum(n) is greater than the value of number.To solve this, we will store all abundant numbers into a set, and for given number n, run a loop for i = 1 to n, and check n and (n – i) are abundant or not.Example#include #include #define N 100005 using namespace std; set getAbundantSet() {   ...

Read More

Check if a given string is a rotation of a palindrome in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 21-Oct-2019 397 Views

Here we will see, one string is palindrome after certain rotation or not. A palindrome is a string that is the same in both directions. A string rotation is a palindrome if that is like AAAAD. this is not a palindrome directly, but its rotation AADAA is a palindrome.To check a string is rotated palindrome or not, then we will check this is a palindrome or not at the first time, after that, rotate it by one character, then check again, this checking will be performed n amount of time, where n is the number of characters.Example#include #include ...

Read More

Check if a circle lies inside another circle or not in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 21-Oct-2019 666 Views

Suppose we have two circles (center points, and the radius values), we have to check one circle is fit inside another circle or not. There are three possible causes.The smaller circle lies completely inside the bigger one, without touching each other. In this case, the sum of the distance between the centers, and the smaller radius, is lesser than a bigger radius. So the smaller one will be inside the bigger one.The second case is the smaller circle is inside the bigger ones, but also touches the circumference of the bigger circle.The third case is, some part of the smaller ...

Read More

Maximum Subarray Sum using Divide and Conquer algorithm in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 21-Oct-2019 1K+ Views

Suppose we have one list of data with positive and negative values. We have to find the sum of contiguous subarray whose sum is largest. Suppose the list is containing {-2, -5, 6, -2, -3, 1, 5, -6}, then the sum of maximum subarray is 7. It is the sum of {6, -2, -3, 1, 5}We will solve this problem by using the Divide and Conquer method. The steps will look like below −Steps −Divide the array into two partsFind the maximum of the following threeMaximum subarray sum of left subarrayMaximum subarray sum of right subarrayMaximum subarray sum such that subarray ...

Read More

Program to Divide two 8 Bit numbers in 8051 Microprocessor

Arnab Chakraborty
Arnab Chakraborty
Updated on 09-Oct-2019 2K+ Views

Here we will see the division operation. This operation will be used to divide two 8-bit numbers using this 8051 microcontroller. The register A and B will be used in this operation. No other registers can be used for division. The result of the division has two parts. The quotient part and the remainder part. Register A will hold Quotient, and register B will hold Remainder.We are taking two number 0EH and 03H at location 20H and 21H, After dividing the result will be stored at location 30H and 31H.AddressValue …20H0EH21H03H …30H00H31H00H …Program      MOV R0, #20H ; set source address 20H ...

Read More

Program to Multiply two 8 Bit numbers in 8051 Microprocessor

Arnab Chakraborty
Arnab Chakraborty
Updated on 09-Oct-2019 2K+ Views

Here we will see how to multiply two 8-bit numbers using this 8051 microcontroller. The register A and B will be used for multiplication. No other registers can be used for multiplication. The result of the multiplication may exceed the 8-bit size. So the higher order byte is stored at register B, and lower order byte will be in the Accumulator A after multiplication.We are taking two number FFH and FFH at location 20H and 21H, After multiplying the result will be stored at location 30H and 31H.AddressValue …20HFFH21HFFH …30H00H31H00H …Program      MOV R0, #20H ; set source address 20H to R0 ...

Read More
Showing 3711–3720 of 3,768 articles
« Prev 1 370 371 372 373 374 377 Next »
Advertisements