Possible Moves of Knight in C++

sudhir sharma
Updated on 17-Apr-2020 07:41:13

993 Views

In this problem, we are given an m*n chessboard with filled positions marked by 1 i.e. if board[i][j] = 1, there is some piece there and we are given the starting position. Our task is to find the total number of possible moves for a knight in the board, if there are all pieces of the same color i.e. no attack will be done.Knight is chess is a piece that can move in all directions with some special sort of move. The moves of Knight in chess are −Two horizontal moves and a vertical move.Two vertical moves and a horizontal ... Read More

Possible Number of Rectangles and Squares in C++

sudhir sharma
Updated on 17-Apr-2020 07:37:24

347 Views

In this problem, we are given an array of N integers denoting the length of n sticks. Our task is to print the count of rectangles and squares that can be created from the sticks of the given length.Let’s take an example to understand the problemInput − array = {5, 5, 7, 7, 1, 4}Output − 1Explanation − a rectangle with sides 5 5 7 7.To solve this problem, we will have to check if rectangles and squares are possible or not.Now, for creating a square or rectangle, there should be two sticks of the same length, 2 for rectangle and 4 for ... Read More

Possible Timings in C++

sudhir sharma
Updated on 17-Apr-2020 07:29:13

65 Views

In this problem, we are given two-digit timing using a glow digit display or seven-segment display (as in calculator). Our task is to calculate the possibility of occurrence of other timings that can occur by glowing or deleting one bit of the display.Seven-segment display is a special display that is used to display digits by glowing lines of the display.Sample of the seven-segment display is −Let’s take an example to understand the problem, Input − 7 5Output −Explanation − For 7, 5 numbers can be used to replace it. They are 9, 3, 8, 0, 7. For 5, 4 numbers ... Read More

Form a Triangle from Array Values in C++

sudhir sharma
Updated on 17-Apr-2020 07:26:45

4K+ Views

In this problem, we are given an array of integers. Our task is to check if the creation of a non-degenerate triangle taking the elements of the array as sides of the triangle.Non-degenerate triangle − it is a triangle that has a positive area. The condition for a non-degenerate triangle with sides a, b, c is −a + b > c a + c > b b + c > aLet’s take an example to understand the problem better −Input − arr[2, 5 ,9, 4, 3]Output − YesExplanation − the triangle formed is 2 3 4.To solve this problem, we ... Read More

Make a Divisible by 3 Number Using All Digits in an Array in C++

sudhir sharma
Updated on 17-Apr-2020 07:23:54

646 Views

In this problem, we are given an array. Our task is to check whether a number generated by using all digits of the elements of the array is divisible by 3. If possible then print “Yes” otherwise print “No”.Let’s take an example to understand the problemInput − arr = {3, 5, 91, }Output − YESExplanation − The number 5193 is divisible by 3. So, our answer is YES.To solve this problem, we will check its divisibility by 3.Divisibility by 3 − a number is divisible by 3 if the sum of its digits is divisible by 3.Now, we will have ... Read More

Possible Two Sets from First N Natural Numbers with Difference of Sums as D in C++

sudhir sharma
Updated on 17-Apr-2020 07:21:44

85 Views

In this problem, we are given two integer N and D. Our task is to check whether it is possible to have to sets from the set of first N natural numbers that have a difference of D.Let’s take an example to understand the problem, Input − N=5 D =3Output − YesExplanation −Out of 1, 2, 3, 4, 5. We can have two sets set1= {1, 2, 3} and set2 = {4, 5}, this will give difference 3. {4+5} - {1+2+3} = 9- 6 = 3For solving this problem, we will have some mathematical calculations.We know, the sum of all number ... Read More

Postfix to Infix in C++

sudhir sharma
Updated on 17-Apr-2020 07:15:33

5K+ Views

In this problem, we are given expression in postfix form and our task is to print the infix form of the expression.Infix expression is an expression in which the operator is in the middle of operands, like operand operator operand.Postfix expression is an expression in which the operator is after operands, like operand operator.Postfix expressions are easily computed by the system but are not human readable. So this conversion is required. Generally reading and editing by the end-user is done on infix notations as they are parenthesis separated hence easily understandable for humans.Let’s take an example to understand the problemInput ... Read More

Postorder Successor of a Node in Binary Tree in C++

sudhir sharma
Updated on 17-Apr-2020 07:12:30

719 Views

In this problem, we are given a binary tree and node. Our task is to print the postorder successor of the node in Binary tree.Binary tree is a special type of tree in which each node can have at max 2 child nodes.Postorder Traversal is a tree traversal technique, in which the first left subtree is traversed than the right subtree and the root is traversed at the end.postorder traversal of the above tree: 8 4 2 7 9 6Let’s take an example to understand the problem.Input − binary tree in above example, node= 7Output − 9Explanation − we can ... Read More

Postorder Traversal of Binary Tree Without Recursion and Stack in C++

sudhir sharma
Updated on 17-Apr-2020 07:03:44

447 Views

In this problem, we are given a Binary tree. Our task is to print the postorder traversal of the binary tree without using recursion and without stack.Binary tree is a special type of tree in which each node can have at max 2 child nodes.Postorder Traversal is a tree traversal technique, in which the first left subtree is traversed than the right subtree and the root is traversed at the end.postorder traversal of the above tree − 8 4 2 7 9 6To traverse the tree without using recursion and stack. We will depth-first search based technique and data will ... Read More

POW Function for Complex Number in C++

sudhir sharma
Updated on 17-Apr-2020 06:58:09

708 Views

pow() or power function is a function used to calculate the power of a number. It is generally used in real numbers. Here, we will see its implementation of complex numbers.Complex numbers are those numbers that can be represented as A + iB, where A is the real part and B is the complex part of the number.The functions for the complex number in c++ are defined in the header file . Here, the pow() method for complex numbers is defined. It finds the complex power of a complex number to some power.The method is applied to complex numbers takes ... Read More

Advertisements