Found 26504 Articles for Server Side Programming

Program to find the maximum number in rotated list in C++

Arnab Chakraborty
Updated on 08-Oct-2020 10:23:53

125 Views

Suppose there is an array, and that is sorted, consider that array is rotated at some pivot, that is unknown to us. So we have to find the maximum from that rotated array. So if the array is like[3, 4, 5, 1, 2], then the output will be 5.To solve this, we will follow these steps −low := 0 and high := last index of array, n := size of array, ans := 0while low arr[mid], then ans := maximum of ans and arr[mid], high := mid – 1else if low = mid, then ans := maximum of ans ... Read More

Program to find minimum amount needed to be paid all good performers in Python

Arnab Chakraborty
Updated on 08-Oct-2020 10:20:11

376 Views

Suppose we have given a list of numbers called ratings, and this is showing the performance scores of coders. Now the manager wants to give Rs 1000 to every coder except if two coders are adjacent, they would like to pay the better performing coder at least Rs 1000 higher than the worse performing one. We have to find the minimum amount the manager can pay following above constraints.So, if the input is like ratings = [1, 2, 5, 1], then the output will be 7000, as the minimum we can pay for each respective coder is [1000, 2000, 3000, ... Read More

Program to check a number can be written as a sum of distinct factorial numbers or not in Python

Arnab Chakraborty
Updated on 08-Oct-2020 10:17:12

238 Views

Suppose we have a positive number n, we have to check whether n can be written as the sum of unique positive factorial numbers or not.So, if the input is like n = 144, then the output will be True, as 4! + 5! = 24 + 120 = 144To solve this, we will follow these steps −fact := 1res := a new listx := 2while fact = res[i], thenn := n - res[i]return true when n is same as 0Let us see the following implementation to get better understanding −Example Live Democlass Solution: def solve(self, n):    fact = 1 ... Read More

How to create a data frame with combinations of values in R?

Nizamuddin Siddiqui
Updated on 07-Oct-2020 16:36:25

595 Views

Suppose we have two values 0 and 1 then how many combinations of these values are possible, the answer is 8 and these combinations are (0,0), (1,0), (0,1), (1,1). In R, we can use expand.grid function to create these combinations but to save it in a data frame, we would need to use as.data.frame function.Example Live Demodf1

How to create a standard normal distribution curve with 3-sigma limits in R?

Nizamuddin Siddiqui
Updated on 07-Oct-2020 16:29:52

414 Views

A standard normal distribution has mean equals to zero and the standard deviation equals to one. Therefore, when we plot it with three sigma limits, we have six points on the X-axis referring to the plus and minus around zero. If the limits are defined then the plotting can be shown with larger width and that will change the display of the curve. We can do this by creating a sequence for the length of the standard normal variable and its density.Consider the below vectors corresponding to the limits and density−x

How to change the size of correlation coefficient value in correlation matrix plot using corrplot in R?

Nizamuddin Siddiqui
Updated on 07-Oct-2020 16:26:27

3K+ Views

The correlation coefficient value size in correlation matrix plot created by using corrplot function ranges from 0 to 1, 0 referring to the smallest and 1 referring to the largest, by default it is 1. To change this size, we need to use number.cex argument. For example, if we want to decrease the size to half then we can use number.cex = 0.5.ExampleConsider the below matrix − Live Demoset.seed(99) M corrplot(cor(M), addCoef.col="black")OutputChanging the size of correlation coefficient value to 0.75 −corrplot(cor(M), addCoef.col="black", number.cex=0.75)OutputChanging the size of correlation coefficient value to 0.30 −> corrplot(cor(M), addCoef.col="black", number.cex=0.30)OutputRead More

Program to find the sum of the absolute differences of every pair in a sorted list in Python

Arnab Chakraborty
Updated on 07-Oct-2020 14:31:59

234 Views

Suppose we have a list of sorted numbers called nums, we have to find the sum of the absolute differences between every pair of numbers in the given list. Here we will consider (i, j) and (j, i) are different pairs. If the answer is very large, mod the result by 10^9+7.So, if the input is like nums = [2, 4, 8], then the output will be 24, as |2 - 4| + |2 - 8| + |4 - 2| + |4 - 8| + |8 - 2| + |8 - 4|.To solve this, we will follow these steps −m ... Read More

How to find the groupwise mean and save it in a data frame object in R?

Nizamuddin Siddiqui
Updated on 07-Oct-2020 16:16:25

439 Views

We often need groupwise mean in data analysis, especially in situations where analysis of variance techniques is used because these techniques helps us to compare different groups based on their measures of central tendencies and measures of variations. It can be done by using aggregate function so that the output can be saved in a data frame object. In the below examples, we can see how it can be done and also check the final object type.ExampleConsider the below data frame − Live Demoset.seed(109) Salary

How to concatenate vector with defined name to a list in R?

Nizamuddin Siddiqui
Updated on 07-Oct-2020 16:54:09

139 Views

The concatenation of vector to a list simply means adding an external vector to the list we already have. For this purpose, we need to defined the vector with list function so that the R program understands that we are adding a list object to another list, otherwise the vector entries will be considered as separate vectors to be added in the list. To understand this in a better way, check out the below examples.Example Live DemoConsider the below list −List1

Program to check robot can reach target position or not in Python

Arnab Chakraborty
Updated on 07-Oct-2020 13:47:26

448 Views

Suppose we have a robot, that is currently sitting in at position (0, 0) (Cartesian plane). If we have list of its moves that it can make, containing N(North), S(South), W(West), and E(East). We have to check whether it can reach at destination coordinate (x, y).So, if the input is like moves = ['N', 'N', 'E', 'E', 'S'], (x, y) = (2, 1), then the output will be True, To solve this, we will follow these steps −temp_coord := [0, 0]for each move in moves, doif move is same as "N", thentemp_coord[1] := temp_coord[1] + 1otherwise when move is same ... Read More

Advertisements