Rearrange Array with O(1) Extra Space Using C++

Sunidhi Bansal
Updated on 02-Nov-2021 06:16:33

864 Views

We are given a positive integer type array, let's say, arr[] of any given size such that elements in an array should value greater than 0 but less than the size of an array. The task is to rearrange an array in such a manner that arr[i] becomes arr[arr[i]] within the given O(1) space only and print the final result.Let us see various input output scenarios for this −Input − int arr[] = {0 3 2 1 5 4 }Output − Array before Arrangement: 0 3 2 1 5 4 Rearrangement of an array so that arr[i] becomes arr[arr[i]] with O(1) extra ... Read More

Find Sample Size for T-Test in R

Nizamuddin Siddiqui
Updated on 02-Nov-2021 06:14:48

4K+ Views

To find the sample size for t test, we can use pwr.t.test function of pwr package, wherever we can pass the arguments for alternative hypothesis such as one-sided or two-sided, significance level, power of the test and difference for two samples.Check out the below examples to understand how it works.Example 1Consider the following code to find sample size for t test −library("pwr") pwr.t.test(power=0.80, d=1, sig.level=0.05, alternative="two.sided")OutputIf you execute the above given code, it generates the following Output for the two-sample t test power calculation −   n = 16.71472    d = 1 sig.level = 0.05    power = 0.8 alternative ... Read More

Rearrange Array in Maximum Minimum Form in C++

Sunidhi Bansal
Updated on 02-Nov-2021 06:11:54

2K+ Views

We are given an integer array which can be arranged in sorted/unsorted manner. The task is to first sort the array if the values are unsorted then arrange the array in such a manner that the first element of array will be the maximum value, second will be the minimum value, third will be the second largest value, fourth will be the second minimest value and so on.Let us see various input output scenarios for this −Input − int arr[] = {7, 5, 2, 3, 4, 9, 10, 5 }Output − Array before Arrangement: 2 3 4 5 5 7 9 10 ... Read More

Concatenate Elements of Equal Size Vectors Alternately in R

Nizamuddin Siddiqui
Updated on 02-Nov-2021 06:10:10

175 Views

If we have multiple vectors and we want to combine the vector elements alternatively then we can use rbind function along with c function.For Example, if we have three vectors say X, Y, and Z as −X = 1, 2, 3 Y = 4, 5, 6 Z = 7, 8, 9Then, we can combine the elements in these vectors alternatively by using the below command −c(rbind(X,Y,Z,)) Example 1To concatenate elements of equal size vectors add the following code to the above snippet −x1

Rearrange Array Elements That Are Multiples of X in Increasing Order

Sunidhi Bansal
Updated on 02-Nov-2021 06:07:45

440 Views

We are given an integer type array as ‘int arr[]’ and an integer type variable as ‘x’. The task is to rearrange all the elements of an array in such a manner that they will be divisible by a given integer value ‘x’ and the arrangement should be in an increasing order.Let us see various input output scenarios for this −Input − int arr[] = {4, 24, 3, 5, 7, 22, 12, 10}, int x = 2Output − Rearrangement of all elements of array which are multiples of x 2 in decreasing order is: 4 10 3 5 7 12 22 24Explanation −we ... Read More

Make Duplicate Factor Levels Unique in R Data Frame

Nizamuddin Siddiqui
Updated on 02-Nov-2021 06:06:58

2K+ Views

The factor with duplicate levels represents grouping data but if we want to convert the grouping data into nominal data then duplicate values must be removed or converted into unique values. To make duplicate factor levels unique in an R data frame, we can use make.unique function.Check out the below Examples to understand how it works.Example 1Following snippet creates a sample data frame −Factor

Divide Each Value in an R Data Frame by 100

Nizamuddin Siddiqui
Updated on 02-Nov-2021 06:06:50

3K+ Views

We sometimes need to perform mathematical operations on all values in the data set. One such operation could be dividing each value by 100.For example, if we have a data frame called df then we can divide each value in df by 100 by using the below command −df[,1:ncol(df)]/100ExampleFollowing snippet creates a sample data frame −x1

Recursive Sum of Digits in N and X in C++

Sunidhi Bansal
Updated on 02-Nov-2021 06:04:24

191 Views

We are given positive integer variables as ‘num’ and ‘x’. The task is to recursively calculate the num ^ x then add the digits of a resultant number till the single digit isn’t achieved and the resultant single digit will be the output.Let us see various input output scenarios for this −Input − int num = 2345, int x = 3Output − Recursive sum of digit in n^x, where n and x are very large are: 8Explanation − we are given positive integer values as num and x with the values as 2345 and power as 3. Firstly, calculate 2345 ^ 3 i.e. ... Read More

Find Groupwise Common Value for a Data Table Object

Nizamuddin Siddiqui
Updated on 02-Nov-2021 05:53:54

185 Views

To find the groupwise common value for a data.table object, we can use Reduce function with intersect function.For example, if we have a data.table object called DT that contains a numerical column say Num and a categorical column say C where C exists at the first position then the groupwise common value can be found by using the command given below −Reduce(intersect,DT[,.(list(unique(Num))),C]$V1)ExampleConsider the below data.table object −Group

Print All Numbers Less Than N with Digits 1 or 3 in C++

Sunidhi Bansal
Updated on 02-Nov-2021 05:53:00

587 Views

We are given an integer variable as N storing the positive integer type value. The task is to recursively print all the numbers less than given value N having digit 1, 3 or the combination of both.Let us see various input output scenarios for this −Input − int num = 40Output − Recursive program to print all numbers less than N which consist of digits 1 or 3 only are: 33 31 13 11 3 1Explanation − we are given a positive integer value as 40 stored in a variable num. Now, we will recursively find out all the numbers containing digits 1, ... Read More

Advertisements