Server Side Programming Articles - Page 1528 of 2650

Program to find length of longest consecutive sequence in Python

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

918 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

255 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

894 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

768 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

232 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

445 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

Program to find length of longest anagram subsequence in Python

Niharikaa Aitam
Updated on 01-Sep-2025 11:59:28

366 Views

In Python, a string is immutable data structure in which sequence of characters are enclosed in double("") or single quotes(''). In some cases, we need to find the length of the longest subsequence of characters that can be rearranged to form a palindrome. This type of subsequence is referred to as a palindromic anagram subsequence. To solve this, we need to count how many characters appear an even number of times and at most one character can appear an odd number of times. An anagram is a word or phrase formed by rearranging the letters of another word or phrase ... Read More

Program to return number of smaller elements at right of the given list in Python

Niharikaa Aitam
Updated on 01-Sep-2025 11:58:58

418 Views

In Python, a list is a ordered and mutable data structure where elements are enclosed in square braces []. In some scenarios, we may need to count how many elements to the right of each element in the list are smaller than it. Using Binary Search with bisect_left() Function The bisect_left() Function of the bisect method is used locate the insertion point for an element in a sorted list to maintain the list's sorted order. The insertion point returned by bisect_left() is the index where the element can be inserted without violating the sort order by placing it before any ... Read More

Advertisements