Found 33676 Articles for Programming

Differentiate a Laguerre series and set the derivatives in Python

AmitDiwan
Updated on 04-Mar-2022 05:22:27

136 Views

To differentiate a Laguerre series, use the laguerre.lagder() method in Python. The method returns the Laguerre series coefficients c differentiated m times along axis. At each iteration the result is multiplied by scl. The argument c is an array of coefficients from low to high degree along each axis, e.g., [1, 2, 3] represents the series 1*L_0 + 2*L_1 + 3*L_2 while [[1, 2], [1, 2]] represents 1*L_0(x)*L_0(y) + 1*L_1(x)*L_0(y) + 2*L_0(x)*L_1(y) + 2*L_1(x)*L_1(y) if axis=0 is x and axis=1 is y.The 1st parameter, c is an array of Laguerre series coefficients. If c is multidimensional the different axis correspond ... Read More

C++ program to count minimum how many minutes after there will be no new angry students

Arnab Chakraborty
Updated on 03-Mar-2022 11:37:58

198 Views

Suppose we have a string S of length n, with only two types of characters, 'A' or 'P'. There are n students in a row, the ith student is angry if S[i] = 'A', if it is 'P' it says S[i] is patient. An angry student at index i will hit patient student in index i+1 in every minute, and for the last student even it he is angry, he cannot hit anyone. After hitting a patient student, that student also gets angry. We have to find the minimum minutes for after that no new students get angry.So, if the ... Read More

C++ program to count number of minimum coins needed to get sum k

Arnab Chakraborty
Updated on 03-Mar-2022 11:24:02

236 Views

Suppose we have two numbers n and k. We have unlimited number of coins worth values 1 to n. We want to take some values whose sum is k. We can select multiple same valued coins to get total sum k. We have to count the minimum number of coins needed to get the sum k.So, if the input is like n = 6; k = 16, then the output will be 3, because (2 * 6) + 4.StepsTo solve this, we will follow these steps −c := (n + k - 1) / n return cExampleLet us see the ... Read More

C++ program to choose some numbers for which there will be no subset whose sum is k

Arnab Chakraborty
Updated on 03-Mar-2022 11:22:14

226 Views

Suppose we have two numbers n and k. We have to choose the maximum number of distinct elements from 1 to n, so that no subset whose sum is equal to k. If we can find then return the chosen numbers.So, if the input is like n = 5; k = 3, then the output will be [4, 5, 2]StepsTo solve this, we will follow these steps −for initialize i := (k + 1) / 2, when i

C++ program to find winner of typing game after delay timing

Arnab Chakraborty
Updated on 03-Mar-2022 11:20:12

324 Views

Suppose we have five numbers s, v1, v2, t1 and t2. Amal and Bimal are playing a typing game, they are playing their game online. In this game they will type a string whose length is s. Amal types one character in v1 milliseconds and Bimal types one character in v2 milliseconds. Amal's network delay is t1 milliseconds, and Bimal's network delay is t2 milliseconds.If the connection delay is t milliseconds, the competition passes for a participant as follows −Exactly after t milliseconds after the game start the participant receives the text to be entered.Right after that he starts to ... Read More

C++ program to count number of minutes needed to increase stick length to form a triangle

Arnab Chakraborty
Updated on 03-Mar-2022 11:07:55

266 Views

Suppose we have three numbers a, b and c. There are three sticks whose lengths are a, b and c. In one minute, we can pick one arbitrary stick and increase its length by 1 cm, but we cannot break sticks. We have to count the minimum number of minutes needed to increase their lengths and we can form a triangle with them.So, if the input is like a = 2; b = 3; c = 5, then the output will be 1, because by increasing any one of a or b by 1, we can make a triangle (a ... Read More

C++ program to check we can make two strings equal by swapping from third string

Arnab Chakraborty
Updated on 03-Mar-2022 11:03:25

301 Views

Suppose we have three strings S, T and U of same length n. For every index i in range 0 to n-1, we must swap U[i] with either S[i] or T[i]. So in total we have performed n swapping operations. We have to check whether after such n operations we can make string S exactly same as T.So, if the input is like S = "abc"; T = "bca"; U = "bca", then the output will be True, because for all i if we swap U[i] with S[i], it will be "bca", and T is already "bca".StepsTo solve this, we ... Read More

C++ program to find maximum possible median of elements whose sum is s

Arnab Chakraborty
Updated on 03-Mar-2022 11:00:07

352 Views

Suppose we have two numbers n and s. We have to find the maximum possible median of an array of n non-negative elements, such that the sum of elements is same as s.So, if the input is like n = 3; s = 5, then the output will be 2, because for the array [1, 2, 2], the sum is 5 and median is 2.StepsTo solve this, we will follow these steps −m := floor of (n / 2) + 1 return floor of (s / m)ExampleLet us see the following implementation to get better understanding −#include using namespace ... Read More

C++ program to find permutation with n peaks

Arnab Chakraborty
Updated on 03-Mar-2022 10:56:54

277 Views

Suppose we have two numbers n and k. We have to construct a permutation A using the numbers from 1 to n which has exactly k peaks. An index i is said to be peak of an array A, if A[i] > A[i-1] and A[i] > A[i+1]. If this is not possible, return -1.So, if the input is like n = 5; k = 2, then the output will be [2, 4, 1, 5, 3], other answers are also possible.StepsTo solve this, we will follow these steps −if k > (n - 1) / 2, then:    return -1 Define an array a of size: 101. for initialize i := 1, when i

C++ program to check three items circularly likes next item or not

Arnab Chakraborty
Updated on 03-Mar-2022 10:51:51

112 Views

Suppose we have an array A with n elements. There are n planes on Earth and they are numbered from 1 to n. The plane with number i likes plane A[i]. A[i] != i. We have to check whether there are three planes p, q, and r where p likes q, q likes r and r likes p.So, if the input is like A = [2, 4, 5, 1, 3], then the output will be True, because the triplet is [2, 4, 1].StepsTo solve this, we will follow these steps −n := size of A for initialize i := 0, ... Read More

Advertisements