Suppose there is a function f(x), that counts number of (p, q) pairs, such that1 < p
Suppose we have a number n. If we have numbers like [1, 2, ..., n] we have to count number ofpossible BSTs can be formed using these n values. If the answer is too large, then mod the result by 10^9+7.So, if the input is like n = 3, then the output will be 14, To solve this, we will follow these stepsa := a list with values [0, 1]m := 10^9+7max_n := 1000for k in range 2 to max_n + 1, doinsert (1 + sum of all elements of the list (a[i] * a[k - i] for all i ... Read More
Suppose, there are n number of balls. The balls are ordered in a fashion 1, 2, 3, 4, ..., n. Now the balls are reversed in order, or ordered in a way n, n-1, n-2, ......, 2, 1. The balls are again reversed in order, this time they are reversed from position 1 to n, or now the order becomes n, 1, 2, ....., n-1. This reversing process is repeated n times and each time the starting position is moved 1 place to the right. We now have to find out the position of a ball initially in position 'index' ... Read More
Suppose, there is a polygon with n vertices, n flipping axis, and n rotation points. The following are true for the flipping axes and rotation pointsIf n is odd, each flipping axis passes through only one vertex and the middle of the opposite side.If n is even, half of the axes pass through a pair of opposite vertex and the other half passes through a pair of opposite sides.Two following axes have an angle of 360/2n.Now, we rotate the polygon provided. We have n different types of rotators, a k-rotator rotates the polygon at axis k clockwise by (360 x ... Read More
A neon number is a number where the sum of digits of the square of the number is equal to the number. Let's take an example.n = 9square = 81sum of digits of square = 8 + 1 = 9So, the number 9 is a neon number.We need to check whether the given number is a neon number or not. If the given number is a neon number, then print Yes else print No.AlgorithmInitialise the number n.Find the square of the number.Find the sum of the digits of the squareIf the sum of digits of the square is equal to ... Read More
Suppose, there is a n x n matrix initialized with 0s. Now, a list is given and it contains some pairs that contain a particular row and a column position. For each item i in the list, the contents of the cells increase by 1 where the row number and the column number are less than the row value and column value of item i in the list. After all the list elements have been traversed, we have to find out the number of cells in the matrix that contains the maximum value. (row and column index start at 0)So, ... Read More
Suppose there are n blocks in a path, and a worker is putting colored tiles on the blocks. The worker is putting blocks in a way, such that if a block number in the path is divisible by 4 or/and 2 but not 42, he puts a colored tile there. We have to find out the number of blocks he can cover if he has started with k number of colored tiles.So, if the input is like k = 16, then the output will be 32.To solve this, we will follow these steps −MOD = 10^9 + 7quotient := floor ... Read More
We are given a number n, we need to find the nearest prime number that is less than n. We can find the number easily if we start checking from the n - 1. Let's see some examples.Input10Output7AlgorithmInitialise the number n.Write a loop that iterates from n - 1 to 1Return the first prime number that you foundReturn -1 if you didn't find any prime that's less than given nImplementationFollowing is the implementation of the above algorithm in C++#include using namespace std; bool isPrime(int n) { if (n == 2) { return true; } ... Read More
Suppose we are given four integer numbers p, q, r, and k. We will use a method called the Russian Peasant Multiplication method and determine the value of (p + q.i)^r = r + s.i. We have to return the value of r mod k and s mod k.So, if the input is like p = 3, q = 0, r = 8, k = 10000, then the output will be (6561, 0) 3^8 = 6561, as q = 0 value of r mod k = 6561.To solve this, we will follow these steps −if r is same as 0, ... Read More
Suppose, we have been provided with two points (p1, q1) and (p2, q2). We have to find out the number of integral coordinates (both the x and y values are integers) if a straight line is drawn between the two given points. The number of points is returned.So, if the input is like p1 = 3, q1 = 3, p2 = 6, q2 = 6, then the output will be 2 If we draw the straight line, we will see that the points (5, 5) and (6, 6) are situated on the straight line.To solve this, we will follow these ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP