Questions tagged [subsequence]

A subsequence is a sequence obtained by deleting some elements and retaining the relative order of the remaining elements. It is a generalization of substring which contains only consecutive elements of the original sequence.

A subsequence is a sequence obtained by deleting some elements and retaining the relative order of the remaining elements. It is a generalization of substring which contains only originally consecutive elements.

303 questions
2
votes
0 answers

Android N - Spanned.subSequence from Html get exception StringIndexOutOfBoundsException on some case

I'm facing this exception on Android N : java.lang.StringIndexOutOfBoundsException line : res.add(new SpannableStringBuilder(in.subSequence(lastImageSpanPosition, spanStart))); I don't know why fromHtml medthod in android N returning different…
Dao Quoc Khanh
  • 613
  • 1
  • 7
  • 13
2
votes
2 answers

Prove that a beheaded subsequence is a subsequence of the same sequence

I am working on an exercise where I came up with a proposition to prove but I am stuck. Hope someone and enlighten my thought. I am defining an inductive proposition that defines subsequence relation, where the elements in first list needs to appear…
Jason Hu
  • 6,239
  • 1
  • 20
  • 41
2
votes
3 answers

Find all array subsequences of a given value

I'm looking for an algorithm that given a list like: [1, 1, 2, 1, 1, 5, 1, 1, 1, 1, 2, 1] can find and return all subsequences of a given value. For example, if given the value 1, the function would return [[1, 1], [1, 1], [1, 1, 1, 1], [1]]. I…
barndog
  • 6,975
  • 8
  • 53
  • 105
2
votes
1 answer

Length and sum of longest increasing subsequence

I wanted to count sum and length of the longest subsequence in the given array t. import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class so { public static void main(String[] args) throws…
Yoda
  • 17,363
  • 67
  • 204
  • 344
2
votes
5 answers

How do you check if one array is a subsequence of another?

I'm looking to explore different algorithms, both recursive and dynamic programming, that checks if one arrayA is a subsequence of arrayB. For example, arrayA = [1, 2, 3] arrayB = [5, 6, 1, 7, 2, 9, 3] thus, arrayA is indeed a subsequence of…
Talen Kylon
  • 1,908
  • 7
  • 32
  • 60
2
votes
2 answers

Longest increasing subsequence 2d

I have n sorted arrays of m integers in fixed order. I need to find a longest increasing subsequence such that every element in the subsequence belongs into exactly one of the arrays. Can I do better than O(n2)?
2
votes
1 answer

Efficient algorithm to print sum of elements at all possible subsequences of length 2 to n+1

I will start with an example. Suppose we have an array of size 3 with elements a, b and c like: (where a, b and c are some numerical values) |1 | 2| 3| |a | b| c| (Assume index starts from 1 as shown in the example above) Now all possible…
Karup
  • 2,024
  • 3
  • 22
  • 48
2
votes
1 answer

Longest, consequent, ascending subsequence of an array

I am stuck doing an assignment for university. The task is to find a recursive and then dynamic programming way to calculate the length of the longest,consequent,ascending subsequence of an array. If the array for example is: {4 , -5 , -3, -2, 5,…
Rard
  • 41
  • 5
2
votes
3 answers

minimum length window in string1 where string2 is subsequence

Main DNA sequence(a string) is given (let say string1) and another string to search for(let say string2). You have to find the minimum length window in string1 where string2 is subsequence. string1 = "abcdefababaef" string2 = "abf" Approaches that i…
Shweta
  • 1,111
  • 3
  • 15
  • 30
1
vote
1 answer

Find index of longest consectuive timespan in pandas time series

I have a time series with gaps (NaN) and I want to find the start and stop index of the longest consecutive sequence where no Nan occurs. I have no clue how to do that. values = [5468.0, 5946.0, np.nan, 6019.0, 5797.0, 5879.0, np.nan, …
till Kadabra
  • 478
  • 9
  • 21
1
vote
2 answers

confusing question of maximum possible weight of a subsequence

The weight of a sequence a0, a1, …, an-1 of real numbers is defined as a0+a1/2+…+ aa-1/2n-1. A subsequence of a sequence is obtained by deleting some elements from the sequence, keeping the order of the remaining elements the same. Let X denote the…
1
vote
3 answers

Check if an array is a subsequence of another array

Given this arrays I want to check if "sequence" is a subsequence of "array", meaning all the numbers exist in the original array and in the same order: array = [5, 1, 22, 25, 6, -1, 8, 10]; sequence = [1, 6, -1, 10]; Not sure why my code doesn't…
1
vote
3 answers

Subsequence match for a simple list and a list of sets?

This is a problem involving subsequences. The ordinary subsequence problem has a list l1 and asks whether another list l2 is a subsequence. For example: l1 = [3, 1, 4, 1, 5, 9] l2 = [3, 1, 5] => True (remove 4, 1, 9) l2 = [4, 3, 5] …
marlon
  • 6,029
  • 8
  • 42
  • 76
1
vote
0 answers

Python Consective Subsequence Generation from list in less than O(n^2)

This is a very common problem for a list of number = [1,2,3] I want to generate all possible consecutive subsequence answer ==> [1],[2],[3],[1,2],[2,3],[1,2,3] I have tried two solutions lst = [1,2,3,4] n = len(lst) for i in range(n): for j in…
1
vote
2 answers

Largest sum of all increasing subsequences of length k

I am currently stuck with the classic longest increasing subsequence problem, but there is a slight twist to it. Instead of just finding the longest increasing subsequence, I need to find the largest sum of all increasing subsequences that are of…
Malice
  • 181
  • 2
  • 13