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
5
votes
2 answers

Find longest quasi-constant sub-sequence of a sequence

I had this test earlier today, and I tried to be too clever and hit a road block. Unfortunately I got stuck in this mental rut and wasted too much time, failing this portion of the test. I solved it afterward, but maybe y'all can help me get out of…
NichD
  • 61
  • 4
5
votes
2 answers

Count number of sub-sequences of given array such that their sum is less or equal to given number?

I have an array of size n of integer values and a given number S. 1<=n<=30 I want to find the total number of sub-sequences such that for each sub-sequences elements sum is less than S. For example: let n=3 , S=5and array's elements be as…
Enigma
  • 179
  • 2
  • 12
4
votes
0 answers

Minimum of maximums of non-contiguous subsequences of size k

Before I start: I hope this question is not a duplicate. I've found a couple of similar ones, but none of them seems to describe exactly the same problem. But if it is a duplicate, I will be glad to see a solution (even if it is different from my…
user20276305
  • 95
  • 1
  • 7
4
votes
0 answers

Range Queries for Longest common subsequence

General problem of Longest common Subsequence ( to be used as LCS hereafter) :- Given two Strings, find the length of LCS present in both of them. A subsequence is a sequence that appears in the same relative order, but not necessarily…
code_it
  • 131
  • 7
4
votes
1 answer

Maximum length of the subsequence such that the bitwise XOR of each consecutive element is is k

I am trying to solve this question where we have to find the maximum length of the subsequence such that XOR of each consecutive element is equal to k. e.g : Array = [3,2,4,3,5] and k=1. Answer would be 3. subsequence = [3,2,3] So far I have tried…
Deepak Yadav
  • 97
  • 1
  • 7
4
votes
1 answer

Find the longest palindromic DNA sub-sequence that has the most mutations on it

I've been trying to do a Dynamic Programming assignment for university but I had no success so far. The problem: Given a DNA string and a list of mutation locations (for exemple, pieces 0 and 2 are mutations), find the longest palindromic…
Orlando
  • 232
  • 2
  • 8
4
votes
2 answers

How to get a subsequence of items across multiple lists from a list of lists?

I am trying to get subsequence of items between 2 lists in a list of lists. For example, if I have list=[[1,2,3,4],[],[6,9],[2],[3],[4]] I want to extract the items ranging from list[0][1] until list[2][1] into another list. This resulting list…
A.Huq
  • 41
  • 2
4
votes
2 answers

Extract an increasing subsequence

I wish to extract an increasing subsequence of a vector, starting from the first element. For example, from this vector: a = c(2, 5, 4, 0, 1, 6, 8, 7) ...I'd like to return: res = c(2, 5, 6, 8). I thought I could use a loop, but I want to avoid…
ClementWalter
  • 4,814
  • 1
  • 32
  • 54
4
votes
1 answer

Find the number of substrings of a String that contain some anagram of another String as a subsequence

We have to find number of substrings of a String that contain some anagram of another String as a subsequence. The substrings are considered different only if there start or end positions differ. String="aba" anotherString="a" Occurence of "a" in…
Cyclotron3x3
  • 2,188
  • 23
  • 40
4
votes
1 answer

Maximum difference in contiguous, fixed-length subsequence

Define the displacement of a sequence to be the difference between the maximum and minimum elements. Given a sequence of integers, find the maximum displacement over all contiguous subsequences of length m. For example, if our sequence is [1, 5, 7,…
Matt Adams
  • 709
  • 4
  • 11
4
votes
3 answers

Find the longest subsequence of string X that is a substring of string Y

I know how to use dynamic programming to solve the problem of finding either the most longest common subsequence or longest common substring given two strings. However, I am having a hard time to come up a solution for the problem of finding the…
Skiptomylu
  • 964
  • 1
  • 13
  • 21
3
votes
1 answer

How to write a Javascript function to get all palindromic subsequences from string in order?

A subsequence is a group of characters chosen from a list while maintaining their order. For instance, the subsequenes of the string abc are [a, b, c, ab, ac, bc, abc]. Now, I need to write a function to return all the palindromic subsequences from…
Kristada673
  • 3,512
  • 6
  • 39
  • 93
3
votes
1 answer

Longest Increasing and Decreasing subsequence (Top-Down with memoization)

Question - Given an array of integers, A of length N, find the length of longest subsequence which is first increasing then decreasing. Input:[1, 11, 2, 10, 4, 5, 2, 1] Output: 6 Explanation:[1 2 10 4 2 1] is the longest subsequence. I wrote a…
3
votes
1 answer

Generate all unique k-subsequences

I am trying to write a Python (at least initially) function to generate all subsequences of some length k (where k > 0). Since I only need unique subsequences, I am storing both the subsequences and partial subsequences in sets. The following,…
3
votes
1 answer

What is the fastest way to find a subsequence of a given sequence that every element before is less and every element after is greater

What is the fastest way to find a subsequence of a given sequence under the condition that for each element x in the subsequence, every element in the given sequence before x is less than x and every element in the given sequence after x is greater…
Victor
  • 1,303
  • 1
  • 10
  • 28
1
2
3
20 21