Find Lowest Missing Integer in Array using Python

Arnab Chakraborty
Updated on 08-Oct-2020 10:25:57

192 Views

Suppose we have a list of numbers called nums, we have to find the first missing positive number. In other words, the lowest positive number that does not present in the array. The array can contain duplicates and negative numbers as well.So, if the input is like nums = [0, 3, 1], then the output will be 2To solve this, we will follow these steps −nums := a set with all positive numbers present in numsif nums is null, thenreturn 1for i in range 1 to size of nums + 2, doif i is not present in nums, thenreturn iLet ... Read More

Find Maximum Number in Rotated List in C++

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

123 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

Find Minimum Amount to Pay 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

Check if a Number Can Be Written as a Sum of Distinct Factorial Numbers in Python

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

236 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

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

Create Data Frame with Combinations of Values in R

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

593 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

Create Standard Normal Distribution Curve with 3 Sigma Limits in R

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

411 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

Change Size of Correlation Coefficient in 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

Find Groupwise Mean and Save in Data Frame Object in R

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

437 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

Sum of 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

Advertisements