In this program, we are given Q queries, each query has a positive integer N. Our task is to create a program to solve queries on sum of odd number digit sums of all the factors of a number in C++.Problem description − To solve each query, we need to find all the factors of the number N. Then add all factors having the digit sum as odd. And return the final sum for each query.Let’s take an example to understand the problem, InputQ = 2, queries = {15, 8}Output8 1ExplanationFor query 1: N = 15, factors of 15 are ... Read More
In this problem, we are given an array of N integers. There are Q queries, each containing an integer value m. Our task to create a program to solve Queries for number of distinct integers in Suffix in C++.Problem description − Here, we will need to find the total number of distinct integers that are present in the subarray from the index (m-1) to (N-1). Where m is the value in each query.Let’s take an example to understand the problem −Inputarray = {2, 6, 1, 2, 7, 6} Q = 2 , queries = {1, 5}Output4 2ExplanationFor m = 1, ... Read More
In this problem, we are given a bitonic Sequence and Q queries. Each query has an integer x. Our task is to print the length of the bitonic sequence after inserting integers after each query. And at the end print the bitonic sequence.Problem description − Here, we are given a bitonic sequence. And there are Q queries, each containing one integer that is to be added to the sequence. We will add elements from each query to the sequence and then return the length of the bitonic sequence. After all the queries are completed, we will print the bitonic sequence.Bitonic ... Read More
In this problem, we are given n points that lie of a 2D plane, each coordinate is (x, y). Our task is two solve queries. For each query, we are given an integer R. We need to find the count of points lying inside the circle, taking the circle’s center at origin and radius R.Problem descriptionFor each query, we need to find the total number of points out of n points that lie inside the circle (i.e. inside the circumference) of radius R and center point origin (0, 0).Let’s take an example to understand the problem betterInputn = 4 2 ... Read More
In this problem, we are given a binary matrix bin[][] of size nXm. Our task is to solve all q queries. For query(x, y), we need to find the number of submatrix of size x*x such that all the elements of array y (binary number).Problem descriptionHere, we need to count the total number of sub-matrix of a given size that consists of only one of the two bits i.e. sub-matrix will all elements 0/1.Let’s take an example to understand the problem, Inputn = 3 , m = 4 bin[][] = {{ 1, 1, 0, 1} { 1, 1, 1, 0} ... Read More
When we create a histogram using hist function in R, often the Y-axis labels are smaller than the one or more bars of the histogram. Therefore, the histogram does not look appealing and it becomes a little difficult to match the Y-axis values with the bars size.To solve this problem, we can use ylim argument of hist function in which the range can be supplied to plot on the Y-axis labels.ExampleConsider the below data and its histogram − Live Demoset.seed(101) x
If an R data frame has numerical columns then it is also possible that there exist zeros in few or all columns and we might be interested in finding the number of non-zero values in a column. This will help us to compare the columns based on the number on non-zero values and it can be done by using colSums.ExampleConsider the below data frame − Live Demox1
When the variables are not continuous but could be ranked then we do not use pearson correlation coefficient to find the linear relationship, in this case spearman correlation coefficient comes into the scene. Since the spearman correlation coefficient considers the rank of values, the correlation test ignores the same ranks to find the p-values as a result we get the warning “Cannot compute exact p-value with ties”. This can be avoided by using exact = FALSE inside the cor.test function.ExampleConsider the below vectors and perform spearman correlation test to check the relationship between them − Live Demox1
A row of an R data frame can have multiple ways in columns and these values can be numerical, logical, string etc. It is easy to find the values based on row numbers but finding the row numbers based on a value is different. If we want to find the row number for a particular value in a specific column then we can extract the whole row which seems to be a better way and it can be done by using single square brackets to take the subset of the row.ExampleConsider the below data frame − Live Demox1
A boxplot shows the median as a measure of center along with other values but we might want to compare the means as well. Therefore, showing mean with a point is likely to be preferred if we want to compare many boxplots. This can be done by using points(mean(“Vector_name”)), if we are plotting the columns of an R data frame then we will reference them instead of vector name.ExampleConsider the below data and the boxplot − Live Demox