Server Side Programming Articles - Page 1692 of 2650

Find a non empty subset in an array of N integers such that sum of elements of subset is divisible by N in C++

Arnab Chakraborty
Updated on 28-Aug-2020 08:06:17

369 Views

Suppose we have an array of n numbers; we have to find a non-empty subset such that the sum of elements of the subset is divisible by n. So, we have to output any such subset with its size and the indices of elements in the original array when it is present.So, if the input is like [3, 2, 7, 1, 9], then the output will be [2], [1 2].To solve this, we will follow these steps −Define one map my_mapadd := 0for initialize i := 0, when i < N, update (increase i by 1), do −add := (add ... Read More

Final state of the string after modification in Python

Arnab Chakraborty
Updated on 28-Aug-2020 08:05:57

159 Views

Suppose we have a string S. The length is n. These n boxes adjacent to each other, a character R at position i represents that i-th box is being pushed towards right. similarly, L at position i represents that i-th box is being pushed towards left, a dot '.' indicates an empty space. Starting from initial configuration, at every time unit, a box being pushed to the right side is able to push next box to right, same action can be applied for the left side also. We have to find the final positions of all boxes when no more ... Read More

fillpoly() function in C

Arnab Chakraborty
Updated on 23-Jul-2020 08:18:25

689 Views

ConceptNow the header file graphics.h contains fillpoly() function which is implemented to draw and fill a polygon such as triangle, rectangle, pentagon, hexagon etc. So this function require same arguments as drawpoly().Syntaxvoid fillpoly( int number, int *polypoints );In this case, number indicates (n + 1) number of points where, n is the number of vertices in a polygon and polypoints points to a sequence of (n*2) integers.Input arr[] = {320, 150, 400, 250, 250, 350, 320, 150};Output Explanation So the declaration of fillpoly() contains two arguments: number specifies (n + 1) number of points where n is indicated as the number of vertices ... Read More

Fill 8 numbers in grid with given conditions in C++

Arnab Chakraborty
Updated on 27-Aug-2020 13:53:49

171 Views

Suppose we want to place 1, 2, 3, 4, 5, 6, 7, 8, into the eight circles in the given figure, in this way that no number is adjacent to a number that is next to it in the sequence.So, if the input is like0-1-10-1-1-1-10-1-10then the output will beTo solve this, we will follow these steps −N := 3, M := 4NOTCONSIDERED := -1Define a function present_in_grid(), this will take grid[N][M], num, for initialize i := 0, when i < N, update (increase i by 1), do:for initialize j := 0, when j < M, update (increase j by 1), ... Read More

Check if a number is Primorial Prime or not in C++

Arnab Chakraborty
Updated on 23-Jul-2020 08:06:23

381 Views

ConceptWith respect of given positive number n, the task is to verify if n is a primorial prime number or not. We have to print ‘YES’ if n is a primorial prime number otherwise print ‘NO.Primorial Prime − With respect of Mathematics, a Primorial prime is defined as a prime number of the form pN# + 1 or pN# – 1 , where pN# is the primorial of pN such that the product of first N prime numbers.Input − n = 7Output − YES7 is Primorial prime of the form pN + 1 for N=2, Primorial is 2*3 = 6 ... Read More

Check if a number is an Achilles number or not in C++

Arnab Chakraborty
Updated on 23-Jul-2020 08:03:56

224 Views

ConceptWith respect of given positive integer n, the task is to verify if n is an Achilles number or not. We have to print 'YES' if N is treated as an Achilles number else print 'NO'.Achilles number: With respect of Mathematics, an Achilles number is defined as a number that is powerful (A number N is said to be Powerful Number if it has been noted that for every prime factor p of it, p^2 also divides it) but not a perfect power.In following, the first few Achilles number are displayed72, 108, 200, 288, 392, 432, 500, 648, 675, 800, ... Read More

Check if a number is a Trojan Numbers in C++

Arnab Chakraborty
Updated on 23-Jul-2020 07:59:54

150 Views

ConceptWith respect of given number n, the task is to verify whether n is a Trojan Number or not. Trojan Number is defined as a number that is a strong number without a perfect power. We can say that a number n is treated as a strong number if, for every prime divisor or factor p of n, p^2 is also a divisor. We can say in another way, every prime factor appears at least twice. We should remember that all Trojan numbers are strong. But it is not true for vice-versa that means, not all strong numbers are Trojan ... Read More

Check if a line at 45 degree can divide the plane into two equal weight parts in C++

Arnab Chakraborty
Updated on 27-Aug-2020 13:29:03

153 Views

Suppose we have n different points (Xi, Yi) in 2D coordinate and each point has a weight Wi, we have to check whether a line at 45 degree can be drawn. So that the sum of weights of points on each side will be same.So, if the input is like[[-1, 1, 3], [-2, 1, 1], [1, -1, 4]], then the output will be True/To solve this, we will follow these steps −n := size of vDefine one map weight_at_xmax_x := -2000, min_x := 2000for initialize i := 0, when i < n, update (increase i by 1), do −temp_x := ... Read More

Check if a king can move a valid move or not when N nights are there in a modified chessboard in C++

Arnab Chakraborty
Updated on 23-Jul-2020 07:54:29

413 Views

ConceptWith respect of given infinite chessboard with the same rules as that of chess and given N knights coordinates on the infinite chessboard (-10^9 {3, 4}Output NoThe king can be able to make valid moves.MethodHere, the knight’s move is unusual among chess pieces. Its movement is towards a square that is two squares away horizontally and one square vertically, or two squares vertically and one square horizontally. So, the complete move looks like the letter “L” in every shape possible (8 possible moves). As a result of this, apply a hash map of pairs to mark all possible coordinates where ... Read More

Check if a key is present in every segment of size k in an array in C++

Arnab Chakraborty
Updated on 23-Jul-2020 07:53:05

454 Views

ConceptWith respect of a given array arr1[] with size of array N, one another key X and a segment size K, the task is to determine that the key X present in every segment of size K in arr1[].Input arr1[] = { 4, 6, 3, 5, 10, 4, 2, 8, 4, 12, 13, 4} X = 4 K = 3Output YesThere are existence of 4 non-overlapping segments of size K in the array, {4, 6, 3}, {5, 10, 4}, {2, 8, 4} and {12, 13, 4}. 4 is present all segments.Input arr1[] = { 22, 24, 57, 66, 35, 55, 77, 33, 24, ... Read More

Advertisements