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
1
vote
1 answer

Minimum number of subsequences required to interleave one string to another

I saw the original question Minimum of subsequences required to convert one string to another, and it's very similar to this quesion 1055. Shortest Way to Form String on LeetCode. Description: Given two strings source and target, return the minimum…
GooT
  • 64
  • 6
1
vote
1 answer

Equal sum subsequence in 2 arrays

Given 2 arrays A and B, select a subsequence X from A and Y from B, sum(X) should be equal to sum(Y). We have to find the number of ways in which we can select this type of subsequences. Number of elements in array can be at most 100 Values in array…
Neha K
  • 13
  • 2
1
vote
0 answers

Finding Longest Weak Twin that occurs as a subsequence of a given sequence

Suppose a[] and b[] are finite sequences of integers in which there are no pairs a[i] = a[j] or b[i] = b[j] for (i != j). Then, a[] and b[] are called weak twins if for all i, a[i] < a[i+1] iff b[i] < b[i+1] (which implies, a[i] > a[i+1] iff b[i] >…
1
vote
1 answer

Why is there Memory Error in recursion function in python?

I wrote a code to get all subsequences of a string using recursion in python. Below is the code. def solve(s): if (len(s)==0): return [""] curr = s[0] res = s[1:] ans = solve(res) for i in ans: …
1
vote
2 answers

Given a spacing, finding the largest sum of numbers in an array

Say we have an array with some numbers in it, and we are given a value d (where d >= 1) that dictates a certain required index. How would we find the largest sum of values bounded by d. Here is an example: arr = [3000, 4000, 2000, 2500, 3500,…
user15676482
1
vote
2 answers

Can someone explain this "Longest Common Subsequence" algorithm?

The Longest Common Subsequence (LCS) problem is: given two sequences A and B, find the longest subsequence that is found both in A and in B. For example, given A = "peterparker" and B = "spiderman", the longest common subsequence is "pera". Can…
joseville
  • 685
  • 3
  • 16
1
vote
0 answers

Minimum of Maximum Difference Between Two Elements of A Subsequence

For any subsequence in a given array, the following quantity is defined as D. D(S) = max(|S[i]-S[j]|) for all 1<=i<=j<=|S|. d is a given quantity. the array is given. we are also given p. **Task : I have to check whether a subsequence of size p…
user90596
  • 11
  • 1
1
vote
3 answers

Finding total number of subsequences in an array with consecutive difference = k

In the given array, I am trying to find the total number of subsequences such that: the difference between the consecutive terms is not greater than 3 the first element of the subsequence is the first element of the array the last element of the…
Amanda
  • 2,013
  • 3
  • 24
  • 57
1
vote
0 answers

find all subsequences whose sum lies between a to b

How do i find all subsequences whose sum lies between a to b efficiently? I tried the general method of first creating subsequences and then checking the condition if it exists between a and b or not. Here's my try. can i also optimize it? in case i…
1
vote
2 answers

Find the longest repeated subsequence of max length N in Python

I have some strings representing the order of events: s1 = 'A->B->E->D->A->C->B->D' s2= 'A->B->C->A->B' s3 = 'A->B->A In each string I want to find all repeating patterns of max length N. import itertools def find_all_comb(event_list,max_events): …
kspr
  • 980
  • 9
  • 23
1
vote
1 answer

Extract all possible subsequences from vector in R

I would like to extract all possible subsequences from a vector of length n. For example if I have c("a","b","c") I would like to find c("a","b","c","ab","ac","bc","abc",""). I can solve this manually with vector of short lengths but the problem…
1
vote
1 answer

Why does this greatest subsequential sum code work?

Rosetta Code has the following task, described here: "Given a sequence of integers, find a continuous subsequence which maximizes the sum of its elements, that is, the elements of no other single subsequence add up to a value larger than this one.…
J. Mini
  • 1,868
  • 1
  • 9
  • 38
1
vote
1 answer

Generate all subsequences of length m from a character array of length n where n >= m in Java language

I was looking for an optimal code in Java for generating all subsequences of length m from a character array of length n, where n >= m. The meaning of subsequence is here: https://en.wikipedia.org/wiki/Subsequence My current psuedocode/algorithm is…
user13626846
1
vote
0 answers

Find the shortest substring that has a subsequence that match other string

For example S = 'ABC' and T = 'ABDDDCABDC', the answer is 'ABDC'. not sure if there's a linear solution for this.
pikapika
  • 11
  • 1
1
vote
1 answer

Dynamic Programming for shortest subsequence that is not a subsequence of two strings

Problem: Given two sequences s1 and s2 of '0' and '1'return the shortest sequence that is a subsequence of neither of the two sequences. E.g. s1 = '011' s2 = '1101' Return s_out = '00' as one possible result. Note that substring and subsequence are…
jess
  • 13
  • 4