Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 371 of 377

Check if a given number divides the sum of the factorials of its digits in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 22-Oct-2019 210 Views

Suppose, we have an integer, we have to find if the number divides the sum of the factorial of its digits. Suppose a number is 19, the sum of factorial of digits is (1! + 9!) = 362881, this is divisible by 19. To solve this, we will take the number, then calculate factorial of each digit and add the sum, if the sum is divisible by the number itself, then return true, otherwise false. Example #include using namespace std; int factorial(int n){     if(n == 1 || n == 0)         return 1;     return factorial(n - 1) ...

Read More

Check if a cell can be visited more than once in a String in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 22-Oct-2019 238 Views

Suppose we have a string with dots (.) and a number, a dot indicates the cell is empty, and if there is a number x in any cell, it indicates that we can move x steps to the right or left within the string. Our task is to check whether we can visit a cell more than once or not. For example, if a string is like "2 . . . 2 . .", then we can visit 4th cell in two different ways. From second cell to two step to right, or from two step left from cell 6. ...

Read More

Check if a binary tree is sorted levelwise or not in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 22-Oct-2019 285 Views

Here we will see how to check a binary tree is level wise sorted or not. The level wise sorted binary tree will be look like below −In each level, the nodes are sorted from left to right, and each layer contains higher value than its previous level.We can solve this problem by performing level order traversal, and keep track of the minimum and maximum elements of current level. Use another variable prev_max to hold maximum value of the previous level. Then compare the minimum value of current level and maximum value of previous level prev_max. If min value is ...

Read More

Check if a binary tree is sorted level-wise or not in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 22-Oct-2019 203 Views

Here we will see how to check a binary tree is level wise sorted or not. The level wise sorted binary tree will be look like below −In each level, the nodes are sorted from left to right, and each layer contains higher value than its previous level.We can solve this problem by performing level order traversal, and keep track of the minimum and maximum elements of current level. Use another variable prev_max to hold maximum value of the previous level. Then compare the minimum value of current level and maximum value of previous level prev_max. If min value is ...

Read More

Flip-flop types and their Conversion in C++

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

Flip-Flops are sequential digital circuits. There are few different types of flip-flops. Here we will see the types of flip-flops and the conversion rules from one flip-flop to another.There are basically four types of flip-flops −SR Flip-FlopD Flip-FlopJK Flip-FlopT Flip-FlopSR Flip-flopSR flip-flop operates with only positive clock transitions or negative clock transitions. Whereas, SR latch operates with enable signal. The circuit diagram of SR flip-flop is shown in the following figure.This circuit has two inputs S & R and two outputs Q(t) & Q(t)’. The operation of SR flipflop is similar to SR Latch. But, this flip-flop affects the outputs ...

Read More

Find minimum and maximum elements in singly Circular Linked List in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 22-Oct-2019 565 Views

Here we will see how to get the minimum and maximum value from one singly circular linked linear list. The basic concept is very simple. The next part of the last node will be pointed to the first node, the first node will also be pointed using start pointer. When we insert some element into the list, after inserting the next part of the newly inserted node will be updated with the address of the start node.Initially the min is assigned with positive infinity, and max is assigned with negative infinity. Now traverse the list from left to right. If ...

Read More

Check if a number is multiple of 5 without using / and % operators in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 22-Oct-2019 792 Views

Here we will see how to check a number is divisible by 5 or not. One simple approach is that if the number mod 5 = 0, then, the number is divisible by 5. But here we will not use / or % operator. To check whether a number is divisible by 5, we have to see the last number is 0 or 5. If that is 0 or 5, the number is divisible by 5, otherwise not. Here we can use some large numbers also as a string to check.Example#include using namespace std; bool isDiv5(string num){    int ...

Read More

Check given array of size n can represent BST of n levels or not in C++

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

We have an array A, we have to check whether the array can represent a BST with n levels or not. As the level is , we can construct a tree in following manner. Assume a number is k, value greater than k moves to right side, and less than k moves to left side. Suppose two lists are there: {50, 20, 9, 25, 10}, and {50, 30, 20, 25, 10}The first one is not valid, but the second one is valid.To check this we can either create a BST and check the height, otherwise use array based approach. The ...

Read More

Check for Identical BSTs without building the trees in C++

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

We have two arrays to represent the elements of the BST. If we take elements from that array from left to right, and form the BST, then by taking from both the arrays, we will make the same BST. We have to check whether both are forming the same or not. But the constraint is we cannot make the BST. Suppose two arrays are {2, 4, 1, 3}, and {2, 1, 4, 3}, then if we see, both of these sequences can form same BST.The approach is simple. As we know, the elements of left subtree are smaller than root ...

Read More

Check for Children Sum Property in a Binary Tree in C++

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

Suppose we have a binary tree. The binary tree is valid when it meets the following property.Each node should contain data value same as the sum of left and right children values. If there are no children at any side, then it will be treated as 0.Suppose a tree is present like below, which meets the given property.There is no such trick to check this, we have to traverse the tree recursively, if the node and both of its children satisfies the property then return true, otherwise false.Example#include using namespace std; class node {    public:    int data; ...

Read More
Showing 3701–3710 of 3,768 articles
« Prev 1 369 370 371 372 373 377 Next »
Advertisements