Found 26504 Articles for Server Side Programming

Program to find length of longest distinct sublist in Python

Niharikaa Aitam
Updated on 01-Sep-2025 12:00:56

426 Views

A distinct sublist is a continuous portion of a list in which all the elements are different from each other. The goal is to find the maximum length of such a sublist within a given list of elements. In Python, a list is an ordered and mutable data structure in which sequence of elements are enclosed in square brackets []. The elements in a list can be of any datatype such as integer, float, string etc., and each element in a list has a unique index position which starts from 0. Using set() function The set() is a built-in function ... Read More

How to find the difference between regression line and the points in R?

Nizamuddin Siddiqui
Updated on 10-Oct-2020 12:28:47

279 Views

The difference between regression line and the points on the scatterplot are actually the residuals, thus we need to calculate the residual from the model object. This can be simply done by using residuals function. For example, if we create a linear model defined as Model between x and y then the residuals will be found as residuals(Model).Consider the below data frame −Example Live Demoset.seed(999) x1

Program to find length of longest consecutive sequence in Python

Niharikaa Aitam
Updated on 01-Sep-2025 12:00:33

893 Views

A Consecutive sequence is a series of numbers where each number follows the previous one without any missing the order like 1, 2, 3, 4. It is a set of numbers where each number appears in increasing order by 1, even if not adjacent. We can find the Consecutive sequences in data structures of Python such as lists, strings, tuple, etc. Using set() function set() is the built-in function in Python which is used to create a Set data structure. This function is used to eliminate the duplicates from the given input. We can use set() function to find the ... Read More

How to convert rows in an R data frame to list?

Nizamuddin Siddiqui
Updated on 10-Oct-2020 12:18:07

2K+ Views

Sometimes each row needs to be treated differently, therefore, we might want to convert those rows into list. This will help us to perform the operations on our row elements separately. To convert the rows into list, we can use split function by defining the number of rows in the data frame.Consider the below data frame −Example Live Demoset.seed(101) x1

Program to find length of longest common substring in C++

Arnab Chakraborty
Updated on 10-Oct-2020 12:15:42

2K+ Views

Suppose we have two lowercase strings X and Y, we have to find the length of their longest common substring.So, if the input is like X = "helloworld", Y = "worldbook", then the output will be 5, as "world" is the longest common substring and its length is 5.To solve this, we will follow these steps −Define an array longest of size: m+1 x n+1.len := 0for initialize i := 0, when i

Program to find length of longest common subsequence in C++

Arnab Chakraborty
Updated on 10-Oct-2020 12:05:58

247 Views

Suppose we have two strings text1 and text2, we have to find the length of their longest common subsequence. As we know a subsequence of a string is a new string generated from the original string with some characters deleted without changing the relative order of the remaining characters. (So for example "abe" is a subsequence of "abcde" but "adc" is not). A common subsequence of two strings is a subsequence that is common to both strings. So If there is no common subsequence, return 0. If the input is like “abcde”, and “ace”, then the result will be 3.To ... Read More

How to combine two matrices to create a block-diagonal matrix in R?

Nizamuddin Siddiqui
Updated on 10-Oct-2020 12:10:13

881 Views

A block-diagonal matrix means that a matrix added to another matrix at the end the last element. For example, if we have a matrix with nine values and the other matrix also has nine values then the second matrix will be added to the first matrix and the elements below first matrix will be zero and the elements above the second matrix will also be zero.Example Live DemoM1

How to find the cube root of negative values in R?

Nizamuddin Siddiqui
Updated on 10-Oct-2020 11:55:32

758 Views

There is no function in R to find the cube root of negative values, hence we need to create that. The code to create the function is as shown below −CubeRoot

Program to find length of longest bitonic subsequence in C++

Arnab Chakraborty
Updated on 10-Oct-2020 12:00:43

224 Views

Suppose we have a list of numbers. We have to find length of longest bitonic subsequence. As we knot a sequence is said to be bitonic if it's strictly increasing and then strictly decreasing. A strictly increasing sequence is bitonic. Or a strictly decreasing sequence is bitonic also.So, if the input is like nums = [0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15], size of sequence 16., then the output will be 7.To solve this, we will follow these steps −increasingSubSeq := new array of given array size, and fill with 1for ... Read More

How to create side-by-side boxplot in base R?

Nizamuddin Siddiqui
Updated on 10-Oct-2020 11:54:02

435 Views

Often, we need to compare continuous variables using boxplots and thus side-by-side boxplots are required. Creating side-by-side boxplot in base R can be done with the help of creating space for graphs with the help of par(mfrow=). In this function, we can define the number of graphs and the sequence of these graphs, thus creation of side-by-side boxplot will become easy.Consider the below vectors −set.seed(100) x

Advertisements