The line equation that should be satisfied is y = mx + c. Given an array, m, and c, we have to find the number of order points satisfying the line equation. Let's see an example.Inputarr = [1, 2, 3] m = 1 c = 1Output2The pairs satisfying the line equation are2 1 3 2AlgorithmInitialise the array, m, and c.Write two loops to get all pairs from the array.Check whether the pair is satisfying the line equation or not.We can check the whether the equation is satisfied or not by substituting the values into the line equation.If the pair satisfies ... Read More
In this tutorial, we are going to write a program that finds the number non-negative integral solution of sum equation.The sum equation is x + y + z = n. You are given the number n, you need to find the number of solutions for the equation. Let's see an example.Input2Output6Solutions are0 0 2 0 1 1 0 2 0 1 0 1 1 1 0 2 0 0AlgorithmInitialise the number m.Initialise the count to 0.Write three nested loops to get all the combinations of three numbers.Check the validation of the equation.If the current numbers satisfies the equation, then increment ... Read More
Given an n-ary tree and a number, we have to count the number of nodes greater than the given number. Let's see an example.Inputtree = [[4], [1, 2], [3, 5]] n = 2Output3There are 3 nodes with values that are greater than n.AlgorithmInitialise the n-ary tree.Initialise the count to 0.Increment the count by 1 when you find a node whose value is greater than n.Get the children of the current node.Iterate over all the children and recursively call the same function to count nodes.Return the count.ImplementationFollowing is the implementation of the above algorithm in C++#include using namespace std; struct ... Read More
You are given an array and the index of the target element. We have to count the number of elements greater than the given element to its right. Let's see an example.Inputarr = [2, 3, 5, 1, 4, 2, 6] index = 3Output3The target index element is 1. There are three elements i.e..., 4, 2, 6 that are greater than 1 on its right side.AlgorithmInitialise the array and index of target element.If the index is greater than or equal to the length of the array, then return -1.Write a loop that iterates from the next element of the given index.Increment ... Read More
The stepping number is a number where the difference between the consecutive digits is 1. You are given a number n representing the number of digits. You need to count the total number of stepping numbers with n digits.Let's see an example.Input2Output17The lowest number of 2 digits is 10 and highest number of 2 digits is 99. There are 17 stepping numbers in between them.AlgorithmInitialise the number n.Initialise the count to 0.Find the lowest number of n digits i.e.., pow(10, n - 1).Find the highest number of n digits i.e.., pow(10, n) - 1.Write a loop that iterates from the ... Read More
Given a number N, we need to find the moves required to guess the permutation in the worst-case scenario. The number of moves required to guess the permutation will be n!. Let's take an example.Input5Output129When we have 5 elements, then we have 5 ways to guess, and 4 ways when we have 4 elements and it continuous till 1.AlgorithmInitialise the number n.Initialise count to 1.Write a loop that iterates from 1 to n.Multiply count with the current number.Return the count.ImplementationFollowing is the implementation of the above algorithm in C++#include using namespace std; int getNumberMoves(int n) { int count ... Read More
In this tutorial, we are going to write a program that finds the number of leaf nodes for every node in the n-ary tree.Given a n-ary tree, we have to find the number of leaf nodes for every subtree. Let's see an example.InputN = 8 tree = [[2, 3], [], [4, 5, 6], [7, 8], [], [], [], []]Output1->5 2->1 3->4 4->2 5->1 6->1 7->1 8->1AlgorithmInitialise the n-ary tree with tree you like.Use the DFS to traverse through the tree.Maintain an array to store the count of each node leaf nodes count.Increment the count of leaf node after the recursive ... Read More
Given a number, we have to find the number of leading zeroes in the binary representation of it. Assuming total bits to be 32. Let's see an example.Input5Output25The binary representation of 5 is 00000...00101. The number of leading zeroes are 29.AlgorithmInitialise the number n.Find the binary representation of n.Subtract the length of binary representation of n from the total number of bits i.e.., 32.Return the result.ImplementationFollowing is the implementation of the above algorithm in C++#include using namespace std; int getLeadingZeroesCount(unsigned int n) { int totalBits = sizeof(n) * 8; string binary = ""; while (n) { ... Read More
Given a string, we have to count the number of larger elements on right side of each character. Let's see an example.Inputstring = "abc"Output2 1 0There are 2 larger elements than a on its right side.There is 1 larger element than b on its right side.There are 0 larger elements than c on its right side.AlgorithmInitialise the string.Initialise an array to keep track of the count.Write two loops to iterate over the string.Take one char at a time and compare it with all the character after it.Increment the corresponding character count in the count array if the current element is ... Read More
To insert a temporary text in a tkinter Entry widget, we will bind the event with the Entry widget and call a user-defined function to delete the text inside the Entry widget.Steps −Import the tkinter library and create an instance of tkinter frame.Set the size of the frame using geometry method.Create a user-defined method "temp_text()" to capture the event and delete the temporary text inside the Entry widget.Create an Entry widget inside the Root window and set its properties such as background color, width, and border width.Use the insert() method of the Entry widget to insert a string ... Read More
 
 Data Structure
 Data Structure Networking
 Networking RDBMS
 RDBMS Operating System
 Operating System Java
 Java MS Excel
 MS Excel iOS
 iOS HTML
 HTML CSS
 CSS Android
 Android Python
 Python C Programming
 C Programming C++
 C++ C#
 C# MongoDB
 MongoDB MySQL
 MySQL Javascript
 Javascript PHP
 PHP 
		